简体   繁体   English

javascript 小书签中的引号

[英]quotation marks in a javascript bookmarklet

I wrote a javascript bookmarklet which works well.我写了一个运行良好的 javascript 小书签。 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: 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?有什么简单的方法可以在 html 代码中编写小书签 javascript 代码吗?

You can URL encode characters in bookmarklets and the bookmarklet will work. 您可以对bookmarklet中的字符进行URL编码,并且bookmarklet将起作用。

But also you can try using a bookmarklet "generator" to make it easier and faster 但您也可以尝试使用书签“生成器”来使其更容易,更快捷

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

This bookmarklet generator was created in 2012 and still works great today: https://mrcoles.com/bookmarklet/这个小书签生成器创建于 2012 年,今天仍然很好用: https://mrcoles.com/bookmarklet/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM