简体   繁体   中英

How do I include HTML bits from another file in a bookmarklet?

I have a bookmarklet written in jQuery where I'm creating elements and adding them to the DOM.

$dot = $('<span class="dot" style="left:0;top:0;" />');
$('body').append($dot);

Is there a way I can include HTML without writing it directly in the .js file? The span above is pretty simple, but how can I create a sophisticated form without making it a maintenance nightmare?

EDIT

To clarify, I know how to load the script via bookmarklet, but I was wondering if there's any easy way to refrence complex pieces of HTML in the .js file so I don't have long, complex, embedded strings of HTML to maintain inside that one file.

Use an ajax request to load some html data from your server, but be sure to add a cache param to your bookmarklet's script include.

document.createElement("script"); , add the source, and append it to the current page somewhere (head, body, it's up to you).

EDIT: I may not have been clear enough, but you will want to load the script file from your domain which would then run any ajax requests. Your bookmarklet would then just become a container to test if the dom is ready and append a script (from your server) if so.

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