0

Suppose that I have a URL like the following:

http://localhost:8000/intranet/users/view?user_id=8823 

Now, all I want to do is to get the value of the URL using JavaScript and parse it, taking the user_id value (which is 8823 in this case) and sending that value through an iframe.

How can I do this?

0

4 Answers 4

1

try this code

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, " ")); } 

i found it at How can I get query string values in JavaScript?

Sign up to request clarification or add additional context in comments.

Comments

0

Try using window.location.href or document.URL

Comments

0

Do this:

var matches = document.location.search.match( /user_id=(\d+)/ ); if ( matches != null ) { alert( matches[ 1 ] ); } 

matches[ 1 ] will contain the user ID. document.location.search contains the query string (all of the parameters which follow the '?' including the '?').

Comments

0
var test = "http://localhost:8000/intranet/users/view?user_id=8823"; //var url = document.URL; var url = test.split("="); var urlID = url[url.length-1]; document.write(urlID); window.frames["myIframe"].yourMethod(urlID); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.