I want to append some JavaScript to another page (any other page that allows it), but I want the code inline and not as another JS-file.
This one works, but then I'm stuck with a static JS-file, and I need to add a variable to it.
<a href="javascript: (function () {var bookmarklet = document.createElement('script'); bookmarklet.setAttribute('src', 'https://example.com/bookmarklet/index.js'); document.body.appendChild(bookmarklet); }());">Bookmarklet</a>
Do I need to do something like document.write
instead of document.createElement
, or should I switch scr
with text
?