SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Guru
    Join Date
    Dec 2008
    Posts
    692
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    getting values from page 1 to page 2 in javasxcript

    i have 2 .aspx (dotnet ) pages

    page 1- i have a function to open a new window with the given url. i am paasiing paramaters thr' this url.

    i want to get the values of the parameters in page2
    currently i can get the paramters in code behind as request.Querystring("Param1);
    but how do i get it in javascript on page2

  2. #2
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,313
    Mentioned
    178 Post(s)
    Tagged
    8 Thread(s)
    Hi there,

    You can use this function:

    Code JavaScript:
    function getParameterByName(name)
    {
      name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
      var regexS = "[\\?&]" + name + "=([^&#]*)";
      var regex = new RegExp(regexS);
      var results = regex.exec(window.location.search);
      if(results == null)
        return "";
      else
        return decodeURIComponent(results[1].replace(/\+/g, " "));
    }

    Say you had a page, where the url is http://localhost/projects/index.html?page=1

    You can then do:

    Code JavaScript:
    console.log(getParameterByName("page"));

    which will output "1"

    I can't take credit for this. i found it on StackOverflow: http://stackoverflow.com/questions/9...-string-values


Bookmarks

Posting Permissions

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