1

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?

Espen Klem
  • 331
  • 2
  • 15
  • Thanks, seems `script.text = "alert('voila!');"` should work. I'll check and mark it as duplicate / solution. – Espen Klem Aug 16 '19 at 07:31

0 Answers0