js框架传值在chrome中出现错误

本文讨论了在一个页面中使用frameset包含多个窗口时,如何在子窗口中调用父窗口属性,并解决了在Chrome浏览器中遇到的跨文件系统访问限制问题。通过将应用部署在Tomcat服务器上并通过URL访问,或直接使用IE浏览器访问,成功实现了不同窗口间的属性交互。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

我在一个页面中frameset包含了两个窗口

 

<html>
<head>
<meta http-equiv="content-type" content="text/type;charset:UTF-8">
</head>
<frameset cols="50%,*">
<frame src="a.html"></frame>
<frame src="b.html"></frame>
</frameset>
</html>

在一个子窗口中调用父窗口的属性

a.html

 

<html>
<head>
<meta http-equiv="content-type" content="text/type;charset:UTF-8">
<script type="text/javascript">
	//button事件
	function btn_onclick(){
		var showArea=document.getElementById("showTxt");
		showArea.value="";
		showArea.value+=(window.parent.location.href+"\n");
		showArea.value+=window.parent.getVisitedStr();
	}
	
	function addpage_onload(){
		alert(window.parent.location.href);
	}
	window.onload=addpage_onload;
</script>
</head>
<body>
	
	<button  onclick="btn_onclick()" >list page visited</button>
</body>
</html>

 

在chrome浏览器中出现错误

Blocked a frame with origin "null" from accessing a frame with origin "null"

 

 

查阅资料后得知chorme浏览器对于在文件系统中的主框架相互访问当做异域访问(既认为是不同服务器之间的访问),所以可以在Tomcat中发布后 再用http://127.0.0.1//xxx 的方式访问 或者之间用IE访问

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值