Nathan Campos
Nathan Campos

Reputation: 29497

Getting a Parameter on The URL

It's common to use URL parameters to show dynamic information, just like here on StackOverflow:

http://stackoverflow.com/questions/1183842

But would that be possible when you're without any language like PHP or others? Is there any way to get that value using JavaScript and capture it inside a variable to present it like this:

<h1>param_variable</h1>

Upvotes: 1

Views: 8384

Answers (2)

Vincent Ramdhanie
Vincent Ramdhanie

Reputation: 103135

In JavaScript you can get the current page's url like this:

   var url = location.href;

You may then need to parse it your self to find the parameter that you are looking for.

Upvotes: 0

Ben
Ben

Reputation: 16553

window.location.href contains the current URL. With some string manipulations you can grab anything you want from it.

In this case:

var url = window.location.href;
var id = url.split('/')[4];
alert(id);

Will alert

4479268

Upvotes: 5

Related Questions