Home > Web Front-end > HTML Tutorial > iframe标签 父子页面传值_html/css_WEB-ITnose

iframe标签 父子页面传值_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:28:40
Original
1469 people have browsed it

1.子页面取父页面的值

采用url 传值的方式   ?+&

<iframe src="child.html?a=1&b=2&c=3"></iframe>
Copy after login

这样,在子页面的js中便可以取值,将物质方法封装为一个FUNCTION

function Request(argname){  			 var url = document.location.href;  			 var arrStr = url.substring(url.indexOf("?")+1).split("&");  			//return arrStr;  			for(var i =0;i<arrStr.length;i++) {  				 var loc = arrStr[i].indexOf(argname+"=");  				 if(loc!=-1){  					 return arrStr[i].replace(argname+"=","").replace("?","");  					 break;  				}  			}  		return "";  		}
Copy after login

这样就可以轻松取出所有的参数值

var a= Request("a");var b= Request("b");var c= Request("c");
Copy after login

2.子页面调用父页面的方法

子页面调用父页面方法,parent.方法名()即可。

var word   =	parent.say();
Copy after login

3.子页面向父页面传参

可以理解为在父页面定义了一个变量,子页面调用该变量并且给它赋值。

window.parent.id="123"
Copy after login

4.父页面调用子页面方法

<iframe name="myframe" src="child.html"></iframe>
Copy after login

调用方法:

myframe.window.functionName();
Copy after login
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