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