Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

This question already has an answer here:

I have a url

http://localhost:8162/UI/UsersDetail.aspx?id_temp=U0001

I want to get string use javascript

?id_temp=U0001

Thank guys.

share|improve this question

marked as duplicate by Community 2 days ago

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
Check this stackoverflow.com/questions/979975/… –  Manashvi birla May 26 at 6:56
    
Atleast do some google..stackoverflow.com/questions/901115/… –  sharad May 26 at 6:57
1  
Do you both realize the links you give don't answer this question (which is probably a duplicate) ? –  Denys Séguret May 26 at 6:57

2 Answers 2

If this isn't the location of the page, you may use

var str = url.match(/\?.*$/)[0];

If this url is the current one of your page, use

var str = location.search;
share|improve this answer

You can use regex:

url.match(/\?(\w+=\w+)/)[0];
  1. / : Delimiter of regex
  2. \? : Matches ? need to escape using \
  3. \w+: Matches all alphanumeric characters and _
  4. = : Matches =
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.