简体   繁体   English

在Bookmarklet中将HTML与JavaScript分离

[英]Decoupling HTML from JavaScript in bookmarklet

(Can't think of a good title :(( ) (想不出好标题:(()

Hey all, 大家好,

I'm developing a bookmarklet. 我正在开发一个书签。 When clicked on it creates a toolbar on the page the user is looking at. 单击它会在用户正在查看的页面上创建一个工具栏。 The above involves pulling various javascript and css files from my server and injecting them into the pages DOM. 以上内容涉及从服务器中提取各种javascript和css文件,并将它们注入页面DOM中。

I don't want to encode toolbar's HTML as a string inside one of my javascripts. 我不想将工具栏的HTML编码为我的一个javascript中的字符串。 So I've tried using hidden iframes to load my toolbar and then grabbing a fragment of html to insert, but immediately ran into cross-domain issues. 因此,我尝试使用隐藏的iframe加载工具栏,然后抓取一段html插入,但立即遇到跨域问题。

One solution spring to mind is sending my toolbar's html in JSON, but that seems a bit "hacky"? 我想到的一个解决方案是使用JSON发送我的工具栏的html,但这似乎有些“ hacky”?

What would be a good solution to the problem avoiding difficult-to-maintain html strings in javascript? 解决避免javascript中难以维护的html字符串的问题的最佳解决方案是什么?

Thanks. 谢谢。

Don't know if it will help, here are 2 examples of toolbar bookmarklets: 不知道是否有帮助,这是工具栏书签的2个示例:

  1. diigolet : www.diigo.com/tools/diigolet diigolet:www.diigo.com/tools/diigolet
  2. fytch it : fytch.com/about/get-started fytch:fytch.com/about/get-started

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

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