Results 1 to 5 of 5

Thread: Javascript - get the address bar arguments

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    1,276

    Question Javascript - get the address bar arguments

    Is there a way in Javascript to get the arguments passed to the url from the address bar?

    If I have a page test.htm and I open it like test.htm?id=99&name=user

    is there a way to get the id and name arguments?

  2. #2
    Frenzied Member vbNeo's Avatar
    Join Date
    May 2002
    Location
    Jutland, Denmark
    Posts
    1,994
    Get them using a server side script, I usually do that...

    <script>
    var var1=<%=Request("var1")%>;
    </script>

    An example using ASP
    "Lies, sanctions, and cruise missiles have never created a free and just society. Only everyday people can do that."
    - Zack de la Rocha


    Hear me roar.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    1,276
    test.htm

    PHP Code:
    <HTML>
    <
    HEAD>
    <
    TITLE>Popup Example</TITLE>

    <
    SCRIPT>

    function 
    ButtonClick()
    {
        
    window.open('temp.htm?id=345'nullnull);
    }
    </
    SCRIPT>
    </
    HEAD>

    <
    BODY>
    <
    BUTTON onclick="ButtonClick()">Open Window</BUTTON>
    </
    BODY>
    </
    HTML
    temp.htm

    PHP Code:
    <HTML>
    <
    HEAD>
    <
    TITLE>Popup Example</TITLE>

    <
    SCRIPT>
        function 
    GetId()
        {
            var 
    var1= <% Request("id") %>;
            
    alert(var1);
        }
    </
    SCRIPT>

    </
    HEAD>

    <
    BODY>

    </
    BODY>
    </
    HTML
    I get a Syntax error on line 7 when temp.htm pops up.

  4. #4
    Frenzied Member vbNeo's Avatar
    Join Date
    May 2002
    Location
    Jutland, Denmark
    Posts
    1,994
    you need = after the <% sign, and the file needs to be renamed to .asp, furthermore does the server you run it from have to support ASP.
    "Lies, sanctions, and cruise missiles have never created a free and just society. Only everyday people can do that."
    - Zack de la Rocha


    Hear me roar.

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    In pure client-side JavaScript you need to parse the url yourself, you can get it from
    location.href
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

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



Click Here to Expand Forum to Full Width