Web Analytics Made Easy -
StatCounter how to parse/set ? to my javascript - CodingForum

Announcement

Collapse
No announcement yet.

how to parse/set ? to my javascript

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • how to parse/set ? to my javascript

    Hi,
    I have noted alot of web pages appear to set/parse data via the url
    how do i access the data from the url name
    how do i set the url name with the data using ?
    Thanks in advance
    ez
    Animation Rule #64
    Poor quality images are often artistic,
    Poor quality sound is ALWAYS annoying.

  • #2
    If the url of a window/frame is like:
    http://www.mysite.com/test.htm?param...extparam=world

    Then you may use the location.search property of the window in script:

    <script>
    var data=location.search.substr(1);// gives everything after the '?'
    var arr=data.split("&");// split into array delimited by '&'
    for (i=0;i<arr.length;i++) {
    arr[i]=arr[i].split("=");//further splits into 2-d array so that arr[0][0]="param" and arr[0][1]="hello"
    }
    // Now use the data
    </script>

    Comment


    • #3
      The above may not parse certain query strings correctly. It will also leave the name/value URL encoded. An alternative choice can be found at http://www.webdeveloper.com/forum/sh...d.php?t=162208
      Last edited by joh6nn; Oct 3, 2007, 07:04 PM. Reason: updated url at user's request

      Comment

      Working...
      X