Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Posts
    436
    Thanks
    1
    Thanked 0 Times in 0 Posts

    parameters in JS

    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!

  • #2
    Regular Coder
    Join Date
    Aug 2002
    Location
    Silicon Valley, CA
    Posts
    980
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    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...

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Posts
    436
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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

  • #4
    Regular Coder
    Join Date
    Aug 2002
    Location
    Spain
    Posts
    420
    Thanks
    0
    Thanked 0 Times in 0 Posts
    What OS/Browser are you using?
    Don't resist to assimilation. Billions of Borgs can't be wrong!

  • #5
    Regular Coder
    Join Date
    Jul 2002
    Posts
    436
    Thanks
    1
    Thanked 0 Times in 0 Posts
    win2k+IE5.5/IE6

    But I think that it's the same for all...

  • #6
    Regular Coder
    Join Date
    Aug 2002
    Location
    Spain
    Posts
    420
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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
    Don't resist to assimilation. Billions of Borgs can't be wrong!

  • #7
    Regular Coder
    Join Date
    Jul 2002
    Posts
    436
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I do this:
    Code:
    <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...

  • #8
    Regular Coder
    Join Date
    Aug 2002
    Location
    Spain
    Posts
    420
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Noooo! I mean the address bar of your browser, where you write urls, not the javascript link.
    Don't resist to assimilation. Billions of Borgs can't be wrong!

  • #9
    Regular Coder
    Join Date
    Jul 2002
    Posts
    436
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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

  • #10
    Regular Coder
    Join Date
    Aug 2002
    Location
    Spain
    Posts
    420
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have no idea. It should work; maybe there's something wrong with your browser
    Don't resist to assimilation. Billions of Borgs can't be wrong!

  • #11
    Regular Coder
    Join Date
    Jul 2002
    Posts
    436
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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

  • #12
    Regular Coder
    Join Date
    Aug 2002
    Location
    Silicon Valley, CA
    Posts
    980
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

    Code:
    <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. ..

  • #13
    Regular Coder
    Join Date
    Jul 2002
    Posts
    436
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I get JS error...
    the file://
    seems like a bad idea...
    Any ideas? Please?

  • #14
    Regular Coder
    Join Date
    Aug 2002
    Location
    Silicon Valley, CA
    Posts
    980
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #15
    Regular Coder
    Join Date
    Aug 2002
    Location
    Silicon Valley, CA
    Posts
    980
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:

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


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •