In the work to embed the IFRAME in HTML and invoke the JS method in it.
The demo on the web is called JS in the IFrame in the method of one click event in HTML.
When the trigger is clicked, the IFrame is already rendered, so it is possible to do so.
Now I have the situation is that without any action, the HTML loaded after the call to the IFrame JS.
The following uses the load () method of jquery and calls its JS after the IFRAME has finished loading.
Parent.html
1 <!DOCTYPE HTML>2 <HTML>3 <Head> 4 <MetaCharSet= "Utf-8"> 5 <title>Ifram Test</title> 6 <Scriptsrc= "Https://cdn.bootcss.com/jquery/1.9.1/jquery.min.js"></Script>7 </Head> 8 <Body>9 Ten <iframeID= "Iframe1"src= "child.html"Height= "500px"width= "500px"> One </iframe> A <Script> - $ (document). Ready (function(){ - $("#iframe1"). Load (function(){ the $("#iframe1")[0].contentwindow.sayhello ('Hello World'); - }); - - }); + </Script> - </Body> + </HTML>
Child.html
1 <!DOCTYPE HTML>2 <HTML>3 <Head> 4 <MetaCharSet= "Utf-8"> 5 </Head> 6 <Body>7 8 <P>This is the IFRAME page</P>9 <Script>Ten functionSayHello (text) { One console.info (text); A } - </Script> - </Body> the </HTML>
Jquery calls the JS in the IFRAME