Manipulating an IFrame

Source: Internet
Author: User

Get child iframe

Contentwindow all browsers support chrome to a server environment to

Contentdocument IE 6 7 not supported

document.getElementById (' iframe_id '). ContentWindow.document.getElementById (' child page element node ');

Window.parent Child Frame Action Parent page

Window.parent.document.getElementById (' parent page element node '). style.csstext=.

Window.top Get top Level page

Window.top.document.getElementById (' topmost page element node '). style.csstext=.

Prevent being nested:

if (window!=window.top) {

Window.top.location.href=window.location.href

}

--------------------------------------------------------------------------------------------------------------- ---

IFrame Adaptive height and width:

function Iframeresize (iframename) {

var Ptar = document.getElementById (iframename);

if (Ptar) {//FF

if (ptar.contentdocument && pTar.contentDocument.body.offsetHeight) {

Ptar.height = PTar.contentDocument.body.offsetHeight;

}//ie

else if (ptar.document && pTar.Document.body.scrollHeight) {

Ptar.height = PTar.Document.body.scrollHeight;

}

}

}

IFrame width Adaptive

function Iframeresizewidth (iframename) {

var Ptar = document.getElementById (iframename);

if (Ptar) {//FF

if (ptar.contentdocument && pTar.contentDocument.body.offsetWidth) {

Ptar.width = PTar.contentDocument.body.offsetWidth;

}//ie

else if (ptar.document && pTar.Document.body.scrollWidth) {

Ptar.width = PTar.Document.body.scrollWidth;

}

}

}

Here's how to use it:

<iframe src= "main.aspx" scrolling= "no" frameborder= "0" height= "100%" id= "MainFrame" width= "100%" onload= ' Iframeresize ("MainFrame"); Iframeresizewidth ("MainFrame"); ></iframe>

Manipulating an IFrame

Related Article

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.