Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Query Parameter from a URL which inturn has some URL with Query parameters

I've the following URL

http://somesite/somepage.aspx

I pass a query parameter value which has another URL with query parameters like this.

http://somesite/somepage.aspx?pageURL=http://someothersite/someotherpage.aspx?param1=value&source=http://anotheronesite/anotherpage

I need to get the pageURL value as the one in the bold letters. But i'm getting

http://someothersite/someotherpage.aspx?param1=value

and i'm not getting the source param. I'm using the following JavaScript function -

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

Any ideas?

like image 918
NLV Avatar asked Nov 06 '22 10:11

NLV


1 Answers

You need to use URL encoding to encode the parameter. Otherwise & is treated as reserved character and belongs to the "base URL".

like image 82
Felix Kling Avatar answered Nov 11 '22 02:11

Felix Kling