简体   繁体   中英

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.

I don't want to encode toolbar's HTML as a string inside one of my javascripts. 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.

One solution spring to mind is sending my toolbar's html in JSON, but that seems a bit "hacky"?

What would be a good solution to the problem avoiding difficult-to-maintain html strings in javascript?

Thanks.

Don't know if it will help, here are 2 examples of toolbar bookmarklets:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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