這篇文章主要介紹了通過window.location.search來獲取頁面傳來的參數,經測試是OK的
1function GetQueryString(name) {
2var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)","i");
3var r = window.location.search.substr(1).match(reg);
4if (r!=null) return (r[2]); return null;
5}
1var sname = GetQueryString("name");
2if(sname!=null)
3{
4var sname_ = decodeURIComponent(sname);
5alert(sname_);
6}
測試
abcd.html?name=xyz
應該彈出xyz