0

What is the best way to insert content into an iframe? I'm working on inserting the following into an iframe:

<script src="node_modules/findinnw/dist/find-in-nw.js"></script>
<script>findInNw.initialize();</script>

jQuery:

var intoiframe = '<script src=\"node_modules\/findinnw\/dist\/find-in-nw.js\"><\/script>\n<script>findInNw.initialize();<\/script>';
$('iframe').contents().find("body").append(intoiframe);

From alert(intoiframe) the string looks alright, but my attempt here doesn't seem to be working.

Context: Working on adding a find on page script (https://www.npmjs.com/package/findinnw) into an iframe since nw.js doesn't have native Ctrl+F.

Barmar
  • 741,623
  • 53
  • 500
  • 612
David
  • 71
  • 6
  • This fails for the same reason that you can't assign a script to `.innerHTML`. The same solution should work for this. – Barmar Feb 24 '23 at 16:47

0 Answers0