简体   繁体   中英

JavaScript parameters from URL

var url = window.location.href;

result:

https://test.com/index.html?Event=90000002

how do I use Javascript to get 90000002 and put it in a variable?

You can use the .split() method

var data=url.split("=")[1]

Should return what you got after '='

Though this is not optimized way but you can still do like this

Use location object and it's search property.

location.search will return ?Event=90000002 . Then use substring to get the value

var a = location.search;
console.log(a.substring(7,a.length))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM