Results 1 to 2 of 2

Thread: JavaScript - Extracting variable from string

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member Datacide's Avatar
    Join Date
    Jun 2005
    Posts
    309

    JavaScript - Extracting variable from string

    I have the following code which works awesome for getting the variables form the URL:

    HTML Code:
    function $_GET(q,s) {
      s = (s) ? s : window.location.search;
      var re = new RegExp('&'+q+'=([^&]*)','i');
      return (s=s.replace(/^\?/,'&').match(re)) ? s=s[1] : s='';
    }
    
    document.getElementById(RefId).value = $_GET('refcode');
    But it doesn't work if I use document.referrer instead of window.location

    If I place window.location into a string and use the string in the function it works. If I place document.referrer in a string and use the string in the function it doesn't work.

    The values of window.location is
    Code:
    http://site.org/Default.aspx?refcode=12345&pageId=890916
    The value of document.referrer is
    Code:
    http://site.org/bluepage.html?refcode=12345
    Any thoughts?
    Last edited by Datacide; Jan 13th, 2011 at 11:23 AM.
    PHP in your FACE!

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