JS in an IFRAME to manipulate the DOM of the parent window, you must understand several objects:
- Parent (if the window is a top-level window, then Parent==self==top)
- Top is the top-level parent window (some windows have several layers of frameset or IFRAME)
- 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
- The jquery library is used here for easy development.
- Get parent window node information only with JS primitive methods and properties
- 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;
- 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;
- 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