JavaScript iframe operation and window calls some methods

Source: Internet
Author: User

Some knowledge of JS operation IFrame
1. Print iframe
eg. Framename.document.execcommand (' print ');
2. Get IFRAME
eg. var Ifr_window = window.frames["FrameName"];
3. Get the elements in the IFRAME
Eg1. Place the element with ID ElementID in the IFRAME as not displayed:
var Ifr_window = window.frames["FrameName"];
Ifr_window.elementid.style.display = ' None ';
EG2. Get the table with ID listtable in the IFRAME

Take a look at the example of JS iframe operation

<iframe src= "1.htm" name= "Ifrmname" id= "Ifrmid" ></iframe>

Scenario One: Use the name attribute of the IFRAME to locate

<input type= "button" name= "button" value= "button"
onclick= "Document.frames (' Ifrmname '). Location.reload ()" >

Or

<input type= "button" name= "button" value= "button"
Onclick= "Document.all.ifrmname.document.location.reload ()" >

Scenario Two: Using the id attribute of the IFRAME to locate

<input type= "button" name= "button" value= "button"
Onclick= "Ifrmid.window.location.reload ()" >

Ultimate solution: When iframe src is another Web site address (cross-domain operation)

<input type= "button" name= "button" value= "button"
onclick= "window.open (document.all.ifrmname.src, ' ifrmname ', ')" >

Look at the parent window page

<script type= "text/web Effects" >

function say () {
Alert ("parent.html------>i ' m at Parent.html");
}

function Callchild ()
{
Document.frames ("MyFrame"). F1 ();
Myframe.window.say ();
}
</script>

<body>
<input Type=button value= "invoke functions in Child.html say ()" onclick= "Callchild ()" >
<iframe name= "MyFrame" src= "child.html" ></iframe>
</body>

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.