Things to note when sharing iframe tags

黄舟
Release: 2017-07-21 11:43:18
Original
1444 people have browsed it
  • The child page accesses the parent parent page variables, functions, page elements

//变量:    
//在父页面中需定义为全局变量    
//子页面中调用    
var childFrameVar= parent.ParentVarName;
 //函数:    
 parent.ParentMethodName();
 
 //页面元素:    
 //通过获取document对象,来对页面元素进行操作    
 parent.document
    parent.window.document
Copy after login
  • The parent page accesses the child page functions, page elements 

//函数
    //做出以下尝试,但alert出来的信息均为undefine    
    FrameName.window.childMethodName();
    document.getElementById('FrameId').contentWindow.childMethod();
    
    //页面元素    
    FrameName.window.document
    document.getElementById('FrameId').contentWindow.document
    document.getElementById('FrameId').contentDocument
Copy after login
  • Notes

  Make sure to operate after the iframe is loaded. If If the iframe starts calling methods or variables before it is loaded, an error will occur.

Try not to call page elements or functions in the child page in the parent page. Try to complete all the interactive operations in the child page.

There are two ways to determine whether the iframe has been loaded:

1. Use the onload event on the iframe

2. Use document.readyState=="complete" to determine

The above is the detailed content of Things to note when sharing iframe tags. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template