开发者

Getting a Parameter on The URL

开发者 https://www.devze.com 2023-01-31 18:59 出处:网络
It\'s common to use URL parameters to show dynamic information, just like here on StackOverflow: http://stackoverflow.com/questions/1183842

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>


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消