injecting external js into self created iframe

前端 未结 2 949
遇见更好的自我
遇见更好的自我 2021-01-25 12:59

So i am trying to inject and external css and js into a self created iframe to provide an extra security layer, there therefore is no cross domain issues.

here is the co

2条回答
  •  暖寄归人
    2021-01-25 13:34

    I think you have to create the script element from the iframe's document object. It should be available as contents[0], which you can pass to insertScript.

    It works if you use appendChild directly on your head node (not the jQuery wrapper):

    $('iframe').contents().find('head')[0].appendChild(script);
    

    http://jsbin.com/enidiv/1/edit

提交回复
热议问题