quotation marks in a javascript bookmarklet

370 Views Asked by At

I wrote a javascript bookmarklet which works well. It is rather long and it contains many single and double quotation marks as in the following toy example:

javascript:html="<a href='www.example.com'>example</a>";document.write(html);

Now I have to publish it on a web page, that is, I have to insert the javascript string as the url attribute inside an < a > tag in the html source code of the page, so:

<a href="javascript:...">this is my bookmarklet</a>

but obviously there is a conflict due to repeated double quotation marks. Is there any simple way I can write the bookmarklet javascript code inside an html code?

2

There are 2 best solutions below

0
On

This bookmarklet generator was created in 2012 and still works great today: https://mrcoles.com/bookmarklet/

1
On

You can URL encode characters in bookmarklets and the bookmarklet will work.

But also you can try using a bookmarklet "generator" to make it easier and faster

https://www.google.com/search?q=bookmarklet+generator