此代码在 IE6 中的第 10 行给出错误。即,var ref = ...;
这里有什么错误?
<html>
<head>
<title>JavaScript Popup Example 3</title>
</head>
<SCRIPT language="JavaScript1.2">
function MyClass()
{
this.OpenWindow = function()
{
var ref = window.open ("http://www.google.com", "mywindow", "location=1,status=1,scrollbars=1,width=100,height=100");
ref.moveTo(0,0);
}
}
</SCRIPT>
<body onload="javascript: new MyClass().OpenWindow()">
<H1>JavaScript Popup Example 3</H1>
</body>
</html>
消息:
A run-time error has occurred.
Do you wish to debug?
Line:10
Error: Access is denied
最佳答案
当您打开包含来自不同域的页面的窗口时,您不会获得对该窗口的引用。 ref 变量为空。
如果你想移动窗口,你必须在没有页面的情况下打开它,移动它,然后在其中加载页面:
var r = window.open ('', 'mywindow', 'location=1,status=1,scrollbars=1,width=100,height=100');
r.moveTo(0,0);
r.location.href = 'http://www.google.com';
关于javascript - IE6 出现 "Access is denied"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1815673/