View Full Version : Help Me Correct Or Debug This Script Please!
Michael
08-18-2002, 11:22 PM
hey
thanks for Scoutt's help, I finally started to work with this script, but I need people to correct this script and help me to debug it.
here is the script
<html>
<head>
<script language="javscript">
function refresher()
{
previewwin = window.open("A.html");
window.previewwin.refresh();
setTimeout("refresher()", 3000);
}
</script>
</head>
<body onload="refresher()">
</body>
</html>
previewwin is the name of a page window for A.html
and I want after I open A.html, have it refresh it self every 3 seconds.
But I am getting error like "Object Expected" and I couldn't find anything wrong with this script, so please help!
simon315
08-18-2002, 11:56 PM
Not sure if this helps but,...
<script language="javscript">
SHOULD BE:
<script language="javascript">
You forgot the 'a' in JavaScript. Try it.
Horus_Kol
08-19-2002, 04:30 AM
do you delimit with ';' in javascript? i haven't ever done that - just the end of the line.
Michael
08-19-2002, 10:22 AM
thanks simon315, it removed one bug, but the Object Expected error is still exist and the script didn't make its effect
and Horus_Kol, ";" is used in the Javascript to state the end of the line, some text books teach me to do it, and some don't emphasize that, I think that's not what cause the bug, but appreciate for help
anyone who can help?
Horus_Kol
08-19-2002, 11:36 AM
sorry Michael, I was kind of rushing through and just asking a question.
previewwin = window.open("A.html");
window.previewwin.refresh();
I don't know much java, but this looks a bit odd to my programmers eyes.
should the second line be:
previewwin.window.refresh();
or
previewwin.refresh();
Hope this is helpful
Jon Hanlon
08-19-2002, 07:08 PM
[Thinking "Wish I had a buck for every time I've seen this one..."]
There is no refresh() method.
There is a location.reload() method.
Use
previewwin = window.open("A.html");
window.previewwin.location.reload();
reload() takes an optional parameter. If you specify reload(true), then script will always get a fresh copy of the page from the server, ignoring any cached copies.
Another problem with your code is that it will create a new popup each time.
<html>
<head>
<script language="javscript">
function refresher() {
if (!previewwin || previewwin.closed) // not exist or closed
previewwin = window.open("A.html");
previewwin.location.reload();
setTimeout("refresher()", 3000);
}
</script>
</head>
<body onload="refresher()">
</body>
</html>
As previewwin is a global variable, and global variables are instantiated as properties of the window object, saying:
window.previewwin
is exactly the same as saying:
previewwin
Michael
08-19-2002, 08:29 PM
thank Jon Hanlon
but how count I still get "Object Expected" error?
Jon Hanlon
08-19-2002, 08:36 PM
Post your code please.
scoutt
08-19-2002, 09:59 PM
Originally posted by Jon Hanlon
[Thinking "Wish I had a buck for every time I've seen this one..."]
There is no refresh() method.
There is a location.reload() method.
Use
previewwin = window.open("A.html");
window.previewwin.location.reload();
reload() takes an optional parameter. If you specify reload(true), then script will always get a fresh copy of the page from the server, ignoring any cached copies.
Another problem with your code is that it will create a new popup each time.
<html>
<head>
<script language="javscript">
function refresher() {
if (!previewwin || previewwin.closed) // not exist or closed
previewwin = window.open("A.html");
previewwin.location.reload();
setTimeout("refresher()", 3000);
}
</script>
</head>
<body onload="refresher()">
</body>
</html>
As previewwin is a global variable, and global variables are instantiated as properties of the window object, saying:
window.previewwin
is exactly the same as saying:
previewwin
thanks Jon for clearing that up. I gave him the refresh method as I read it in the javascript manual. but looking further it seems that it is used for plugins. Sorry Michael, but I also learned somethign on this one as well. at least I was close :P
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.