Monday, May 20, 2024
84
rated 0 times [  85] [ 1]  / answers: 1 / hits: 25228  / 9 Years ago, thu, april 16, 2015, 12:00:00

I'm trying to write entries to the console that would contain links to trigger javascript functions upon clicking on them:



console.log(javascript:alert('Hello World'););
console.log(<a href=javascript:alert('Hello World');/>test</a>);
console.log([DisplayObject 'Hello World' <a href=javascript:alert('Hello World');>reveal</a>]);


All these attempts fail.



screenshot



Is there any way to print it similarly to an http://... link, like so...



example



... only, have the text linked to a javascript statement or function instead?



The reason I'm doing this is to be able to quickly reveal which items on the screen are tied to a specific log entry (example: Making a CreateJS sprite scale-up when the log entry is clicked on).


More From » google-chrome

 Answers
6

The Google Chrome console, like many other browser's developer tools consoles, automatically parses any URL into a link to that exact page. This is the only way of obtaining such URLs, and, unfortunately, you cannot actually log custom URLs.



This means that the following logs will be turned into a clickable link automatically:



console.log('http://example.com');
console.log('www.example.com');
console.log('ftp://mysite.com');
console.log('chrome://history')
console.log('chrome-extension://abcdefg...');


but, on the contrary, the following ones won't:



console.log('example.com');
console.log('<a href=http://www.example.com>Link</a>');
console.log('javascript:doSomething(someValue);');

[#67041] Wednesday, April 15, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
janjadonb

Total Points: 4
Total Questions: 114
Total Answers: 118

Location: Mali
Member since Fri, Dec 3, 2021
3 Years ago
janjadonb questions
;