Home > Web Front-end > JS Tutorial > Detailed explanation of iframe page operation examples

Detailed explanation of iframe page operation examples

零下一度
Release: 2017-06-30 16:24:53
Original
1754 people have browsed it

1) Method to find the parent page element in the iframe:
$('#id', window.parent.document)

2) Call the method defined in the parent page in the iframe and Variable:
parent.method
parent.value

3) Example

1. Parent page

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="IframeDemo._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " 
<html xmlns="www.w3.org/1999/xhtml" ><head runat="server">    <title></title>    
<script language="javascript" type="text/javascript" src="jquery-1.5.1.min.js"></script>    
<script language="javascript" type="text/javascript">        var hello = &#39;hello&#39;;        
function getHelloWorld() {            alert(&#39;hello world&#39;);        }    
</script></head><body>    <form id="form1" runat="server">    <div>    
<div id="default" style=" width:200px; height:400px; float:left;">default.aspx</div>    
<iframe id="iframeid" src="IFrame.aspx" style=" width:400px; height:400px; float:left;">
</iframe>    
</div>    </form>
</body></html>
Copy after login

2. Child page

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="IFrame.aspx.cs" Inherits="IframeDemo.IFrame" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " 
<html xmlns="www.w3.org/1999/xhtml" ><head runat="server">    <title></title>    
<script language="javascript" type="text/javascript" src="jquery-1.5.1.min.js"></script>    
<script language="javascript" type="text/javascript">        $(function() {            
//在iframe中查找父页面元素            alert($(&#39;#default&#39;, window.parent.document).html());            
//在iframe中调用父页面中定义的方法            parent.getHelloWorld();            
//在iframe中调用父页面中定义的变量            alert(parent.hello);        });    
</script></head><body>    <form id="form1" runat="server">    
<div id="iframe">        
IFrame.aspx    </div>    
</form>
</body>
</html>
Copy after login

The above is the detailed content of Detailed explanation of iframe page operation examples. 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