【发布时间】:2012-12-26 09:42:20
【问题描述】:
我已经从这个网站收到了 javascript 代码。
alert(window.frames['sc_frame'].document.getElementsByTagName('body')[0].innerHTML);
或
alert(window.frames['sc_frame'].document.getElementsByTagName('body')[0].innerText);
问题是我遇到了这个错误。
Unsafe JavaScript attempt to access frame with URL http://xxxxxxxxxxxxxxxxxxxxxxxxxxxxx from frame with URL http://xxxxxxxxxxxxxxxxxxxxxxxxxxxxx. Domains, protocols and ports must match.
(anonymous function)
InjectedScript._evaluateOn
InjectedScript._evaluateAndWrap
InjectedScript.evaluate
TypeError: Cannot call method 'getElementsByTagName' of undefined
arguments: Array[2]
get message: function () { [native code] }
get stack: function () { [native code] }
set message: function () { [native code] }
set stack: function () { [native code] }
type: "non_object_property_call"
__proto__: Error
我也理解原因,因为我的IFrame 正在调用另一个域。
<iframe id="sc_frame" src="http://example1.com"></iframe>
我使用来自http://example.com 的上述代码。
我的问题是是否有解决方法。使用 javascript 或任何其他方法?
【问题讨论】:
标签: javascript asp.net iframe