0%

JS-获取url参数

window.location.href携带参数到test.html页面。test.html页面获取携带的参数。

JS-获取url参数

window.location.href携带参数到test.html页面。test.html页面获取携带的参数。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<script>
// 前一个页面跳转到test.html并传递参数
// window.location.href = "http://127.0.0.1:8848/a/test.html?pdfId=1";

// test.html获取参数
var pdfId = getQueryString("pdfId");
console.log(pdfId);

function getQueryString(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if (r != null) return unescape(r[2]);
return null;
}
</script>