简体   繁体   中英

“Access is denied” error in IE6

This code is giving me error on line 10 in IE6. That is, var ref = ...;

What is the error here?

<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> 

The message:

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

Line:10
Error: Access is denied

When you open a window with a page from a different domain, you don't get a reference to the window back. The ref variable is null.

If you want to move the window, you have to open it without a page, move it, then load the page in it:

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';

the problem is here - ref.moveTo(0,0); - on most security settings this action is unavailable

also, javascript: on onload just creates a label "javascript"

<html>
<head>
 <title>JavaScript Popup Example 3</title>
</head>
<SCRIPT language="JavaScript">
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="new MyClass().OpenWindow()">
<H1>JavaScript Popup Example 3</H1>
</body>
</html>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM