How to add JavaScript code into existing iFrame using jQuery?

前端 未结 8 2121
借酒劲吻你
借酒劲吻你 2020-12-13 08:13

I want to add a JavaScript snippet into an existing iFrame in the page using jQuery. I have the following code...

Code:

content = \"

        
8条回答
  •  -上瘾入骨i
    2020-12-13 08:25

    This worked for me, paste following code in the page which is in an iframe, not the parent page:

    window.myFunction = function(args) {
       alert("script from iframe");
    }
    

    And now add following code to call above function:

    var iframe = document.getElementById("iframeId");
    iframe.contentWindow.myFunction(args);
    

提交回复
热议问题