【发布时间】:2013-10-24 18:02:47
【问题描述】:
这是我在http://my-localhost.com/iframe-test.html上的代码
<html>
<head><title>Welcome Iframe Test</title></head>
<body>
<iframe src="http://www.my-website.com/index.html" width="500" height="500"></iframe>
<script type="text/javascript">
function alertMyMessage(msg){
alert(msg);
}
</script>
</body>
</html>
这是http://www.my-website.com/index.html上的代码
<html>
<head></title>Welcome to my Server</title></head>
<body>
<h1>Welcome to My Server</ht>
<a href="javascript:void(0)" title="Click here" onClick="parent.alertMyMessage('Thanks for Helping me')">Click Here</a>
</body>
</html>
当我单击“单击此处”链接时。我得到以下错误。
Uncaught SecurityError: Blocked a frame with origin “http://www.my-website.com”来自访问具有原点的框架 “http://my-localhost.com”。协议、域和端口必须匹配。
请帮我解决这个问题,或为此提供一些其他解决方案。
【问题讨论】:
-
你为什么要使用 IFrames?
-
那么为此我可以使用什么?实际上我的目的是我有固定的 html 页面,它将打开许多网站。而那些网站用户必须点击一个链接,并且该链接应该在固定的html页面中调用一个函数。
标签: javascript html iframe cross-domain