View Full Version : parameters in JS
ShMiL
01-11-2003, 10:42 AM
Is it possible to build one html page which refreshes itself and sends following parameters, something like this:
a.htm?id=1
will refresh (or redirect) to:
a.htm?id=2 (=1+1)
will refresh (or redirect) to:
a.htm?id=3 (=2+1)
and so on...
is it possible?
Thanks.
PS
I know how to do it with server-side scripting, so only JS suggestions, guys!
Skyzyx
01-11-2003, 11:02 AM
idVal=location.href.split('?id=');
idURL=idVal[0];
idInt=parseInt(idVal[1]);
location.href=idURL+'?id='+(idInt+1);
I haven't tested it, but I don't see why it wouldn't work...
ShMiL
01-11-2003, 01:49 PM
It works.
But another problem came up: my OS tries to find a file called: "a.htm?id=1" (it doesn't consider the '?' sign and the id as parametes, but as file extension).
Any idea?
I want a page which will refresh every 20 secs and will show following numbers: at the first time, it'll show "1" then "2" then "3"... and so on.
PLEASE HELP!
Thanks,
Shmil
Borgtex
01-11-2003, 02:56 PM
What OS/Browser are you using?
ShMiL
01-11-2003, 03:10 PM
win2k+IE5.5/IE6
But I think that it's the same for all...
Borgtex
01-11-2003, 03:24 PM
I see... you write in the adress bar "a.htm?id=1" and says something like "Windows can't find the file...." right?
to see local files in this way, you have to write "file://" before the name and path:
i.e: file://C:\My documents\a.htm?id=1
ShMiL
01-11-2003, 03:35 PM
I do this:
<html>
<head>
<script language="javascript" type="text/javascript">
<!--
function aimwindow() {
idVal=location.href.split('?id=');
idURL=idVal[0];
idInt=parseInt(idVal[1]);
setTimeout('location.href='file://'+idURL+'?id='+(idInt+1);',6000);
}
// -->
</script>
</head>
<body onload="javascript:aimwindow();">
</body>
</html>
and I get an error from JS...
Borgtex
01-11-2003, 03:42 PM
Noooo! I mean the address bar of your browser, where you write urls, not the javascript link.
ShMiL
01-11-2003, 03:52 PM
Oh sorry.
I changed it to what it was before and tried putting file:// before the htm file path.
It still "can't find" (it's because the OS sees ".htm?id=2" as a file extension just like: ".htm" or ".html" and not as paramteters)...
Is there other ways to do what I need?
Thanks
Borgtex
01-11-2003, 04:18 PM
I have no idea. It should work; maybe there's something wrong with your browser
ShMiL
01-11-2003, 04:29 PM
I think your'e wrong.
HTML is static - so the OS (not the browser) identifies "
.htm?id=1" as new extension (not ".htm").
It has no problem with dynamic pages (like ".asp")...
Anyone else? any other ways to do it?!
Thanks
Skyzyx
01-11-2003, 08:21 PM
Oh yeah, I forgot... Internet Explorer is retarded.
You can modify the script so that if there is no ?id=x, then it will add it.
<html>
<head>
<script language="javascript" type="text/javascript">
<!--
function aimwindow() {
if (location.href.indexOf('?id=') != -1) {
idVal=location.href.split('?id=');
idURL=idVal[0];
idInt=parseInt(idVal[1]);
setTimeout('location.href='file://'+idURL+'?id='+(idInt+1);',6000);
}
else location.href=location.href+'?id=1';
}
// -->
</script>
</head>
<body onload="aimwindow();">
</body>
</html>
Something like this should work. ..
ShMiL
01-11-2003, 08:27 PM
I get JS error...
the file://
seems like a bad idea...
Any ideas? Please?
Skyzyx
01-11-2003, 08:38 PM
Yes! Get rid of the file:// part... who added that? The location.href part already reads the file:// part... and is writing it in so that the computer thinks it's
file://file:///c:/my documents/a.htm?id=1
You don't want that.
Gimme a minute... BRB
Skyzyx
01-11-2003, 08:41 PM
That... AND you can't use the same type of quotes for setTimeout like that... you want to change the outer quotes to double-quotes... like this:
<html>
<head>
<script language="javascript" type="text/javascript">
<!--
function aimwindow() {
if (location.href.indexOf('?id=') != -1) {
idVal=location.href.split('?id=');
idURL=idVal[0];
idInt=parseInt(idVal[1]);
setTimeout("location.href=idURL+'?id='+(idInt+1);",6000);
}
else location.href=location.href+'?id=1';
}
// -->
</script>
</head>
<body onload="aimwindow();">
</body>
</html>
ShMiL
01-11-2003, 08:54 PM
You Are The BEST!
Thanks alot!!!!
ShMiL
01-12-2003, 11:18 AM
another question.
Let's say I open a popup from a HTM file, and that popup redirects to someplace.
Is it possible to CLOSE the popup window FROM the page that poped it?
Thanks.
vkidv
01-12-2003, 02:21 PM
try this, i think this will work:
note:xxx is the name of the popup window
xxx.window.close()
...is that what you want ?
you could place that in a link:
<a href="javascript:xxx.window.close()">Close popup window.<a/>
or a timeout in the main window (i am not sure if this is right)
settimeout("xxx.window.close()",6000)
i hope it helps :D
ShMiL
01-12-2003, 04:03 PM
I'm afraid it doesn't work...
Borgtex
01-12-2003, 05:23 PM
To open
x=window.open(......)
to close
x.close()
ShMiL
01-12-2003, 05:28 PM
Yeah baby!
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.