views:

81

answers:

2

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

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>
glebm
javascript security settings... in ie6? o_O
David Hedlund
No. The same error is occurring. You can test it on your own IE.
JMSA
+5  A: 

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';
Guffa
Wow, you learn something more annoying about IE6 every day...
Rory