Jquery calls the JS in the IFRAME

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.