javascript:function gcloak() { var link = document.querySelector("link[rel*='icon']") || document.createElement('link');link.type = 'image/x-icon';link.rel = 'shortcut icon';link.href = 'https://ssl.gstatic.com/docs/doclist/images/infinite_arrow_favicon_5.ico';document.title = 'My Drive - Google Drive';console.log(document.title);document.getElementsByTagName('head')[0].appendChild(link) };gcloak();setInterval(gcloak, 1000);
I am trying to add this code to a hyperlink so i will be able to drag it to my bookmarks bar. The issue is that it won't include the double quotation marks at
("link[rel*='icon']")
and just ends at
javascript:function gcloak() { var link = document.querySelector(
I have tried changing the double quotes to single quotes but that makes the javascript not work.
CodePudding user response:
if you use backticks (`) instead of double or single quotes then you can write any of single double and even multiline inside it.
`link[rel*='icon']`
CodePudding user response:
Encode double quotes in attributes using "
:
<a href="javascript:console.log("clicked!")">Bookmark me</a>
Browsers don't execute javascript:
URLs when clicked, but you can hover over the link to see the unescaped URL, and presumably it works when bookmarked.