1

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>
CloudJake
  • 156
  • 4
  • 22
Nathan Campos
  • 28,769
  • 59
  • 194
  • 300

2 Answers2

5

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
Ben
  • 16,275
  • 9
  • 45
  • 63
0

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.

Vincent Ramdhanie
  • 102,349
  • 23
  • 137
  • 192