views:

144

answers:

2

Hello all

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?

A: 

have u considered html url encoding the pageURL parameter?

this would greatly simplify your task

elmac
Let me give it a try.
NLV
Okie, can you explain how it would help me?
NLV
No clues. Getting stuck in the same issue. Any ideas?
NLV
easy...everything after the first "=" in your name is your parameter.just decode it back and you got yourself an url.
elmac
or to say it plain:your script should work given the pageURL thingy is encoded.just don't forget to encode it back.jquery has htmlEncode and htmlDecode ;)
elmac
NLV
@NLV: This is HTML encoding, you need URL or percentage encoding.
Felix Kling
HTML encoding is wrong!
Felix Kling
yes sorry i meant URLencode/decode...
elmac
+1  A: 

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

Felix Kling
Thank you. It worked great.
NLV