5

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?

Felix Kling
819k181 gold badges1.1k silver badges1.2k bronze badges
asked Aug 2, 2010 at 16:51
9
  • Where do you get the name/URL from? Commented Aug 2, 2010 at 17:06
  • I set in the code behind - C#. Commented Aug 2, 2010 at 17:17
  • I want everything pageURL. It is not going to change. Can i do it? A specific function taking pageURL as parameter is fine. Commented Aug 2, 2010 at 17:40
  • 1
    @NLV: I have no clue about C# but maybe this helps you: stackoverflow.com/questions/1380617/request-url-parameter Anyway, you have to encode the & so that it is not recognized as parameter of the "base URL". Commented Aug 2, 2010 at 17:40
  • 1
    @NLV: HTML encoding != URL encoding: en.wikipedia.org/wiki/Percent-encoding Commented Aug 2, 2010 at 17:44

2 Answers 2

2

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

answered Aug 2, 2010 at 17:48

Comments

0

have u considered (削除) html (削除ここまで) url encoding the pageURL parameter?

this would greatly simplify your task

answered Aug 2, 2010 at 16:56

6 Comments

Okie, can you explain how it would help me?
No clues. Getting stuck in the same issue. Any ideas?
easy...everything after the first "=" in your name is your parameter. just decode it back and you got yourself an url.
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 ;)
Okie when i encode it just & is replaced by &amp. Nothing else. So still & is preceeding the source link and it is not fetched by that JS function.
|

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.