0

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?

tic
  • 4,009
  • 15
  • 45
  • 86
  • 2
    escape one or both types of quotes – c69 Jan 27 '12 at 00:03
  • 1
    does replacing `"` with `%22` work? (in your href. so it'd be ``) – TJ Ellis Jan 27 '12 at 00:04
  • 2
    there's also this website, that will encode all possible characters for your url: http://jlpoutre.home.xs4all.nl/BoT/Javascript/Utils/endecode.html I don't know whether this will work in your situation or not. – TJ Ellis Jan 27 '12 at 00:06

2 Answers2

2

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

DG.
  • 3,417
  • 2
  • 23
  • 28
0

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