Goto: Gets the parent element window and the height of the element inside the child page loaded by the IFRAME

Source: Internet
Author: User

JS in an IFRAME to manipulate the DOM of the parent window, you must understand several objects:

    1. Parent (if the window is a top-level window, then Parent==self==top)
    2. Top is the top-level parent window (some windows have several layers of frameset or IFRAME)
    3. Self is the current window (equivalent Windows)

Parent page: index.html

<!doctype html>

child window: children.html

 <!doctype html> " utf-8   ><title> child windows </title> http://ajax.googleapis.com/ Ajax/libs/jquery/1.9.1/jquery.min.js   ></script><script >$ (function () {  Window.top;    Alert ($ (p_window). Height ());  var  P_demo = window.top.document.getElementById ( '  

Description

    1. The jquery library is used here for easy development.
    2. Get parent window node information only with JS primitive methods and properties
    3. Gets the height of the parent window: First gets the DOM node of the parent window and then transforms it into a jquery object through the jquery library's $ method, outputting the height of the parent window through the jquery HTML () method;
    4. Gets the height of the parent element: first gets the DOM node of the id= "demo" element in the parent window and then transforms it into a jquery object through the jquery library's $ method, outputting the height of the id= "demo" element through the jquery HTML () method;
    5. PS: Since can be obtained, of course, can also modify the properties or content ...

Article reproduced from: Asked»iframe loaded sub-page inside gets the parent element window and the height of the element.

Goto: Gets the parent element window and the height of the element inside the child page loaded by 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.