This code is 开发者_JAVA技巧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>
精彩评论