IE6中的"访问被拒绝"错误

use*_*312 2 javascript window-object internet-explorer-6

这段代码在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> 
Run Code Online (Sandbox Code Playgroud)

消息:

A run-time error has occurred. 
Do you wish to debug? 

Line:10
Error: Access is denied
Run Code Online (Sandbox Code Playgroud)

Guf*_*ffa 6

当您打开一个包含来自不同域的页面的窗口时,您不会获得对该窗口的引用.ref变量为null.

如果要移动窗口,则必须在没有页面的情况下打开它,移动它,然后在其中加载页面:

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';
Run Code Online (Sandbox Code Playgroud)