0

I have a url that looks something like this:

http://sitename.com?url=domin.com

and I need to take the part of the url after the Equal sign How do I display the value after the equal sign

1 Answer 1

1

in php, you do:

<?=$_GET['url']?>

In java you do :

var split = location.search.replace('?', '').split('=')

split[0] is your var name, and split[1] is your var value. You actually don't really need jQuery for that piece of code ;)

Splitting multiple variables can be done like that:

var split = location.search.replace('?', '').split('&').map(function(val){
  return val.split('=');
});

You can access variable name by split[index][0] and value by split[index][1].

Of course you can use the second snippet instead of the first one for one variable too.

Or, for jQuery, you could use this plugin : https://github.com/mattsnider/jquery-plugin-query-parser

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

3 Comments

Very good Thank you I want using your javascript code But the problem came What is wrong in this code? <script> var split = location.search.replace('?', '').split('=') window.location = "http://"split[1]"" </script>
You are using it wrong:D Try this: var split = location.search.replace('?', '').split('=') window.location; then, on the second line you do: alert(split); OR you do console.log(split);, in which case, in google chrome you right click somewhere on the page, select "inspect element", then you click console and refresh..you should have the values there!
Yes Thank you so much I wanted something that was

Your Answer

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.