JS-获取url参数 发表于 2020-08-12 更新于 2024-03-18 分类于 前端 阅读次数: 本文字数: 561 阅读时长 ≈ 1 分钟 window.location.href携带参数到test.html页面。test.html页面获取携带的参数。 JS-获取url参数window.location.href携带参数到test.html页面。test.html页面获取携带的参数。 123456789101112131415<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> 打赏 微信支付 支付宝 本文作者: 追逐 本文链接: http://blog.xiaoruiit.com/2020/08/12/前端/JS-获取url参数/ 版权声明: 本博客所有文章除特别声明外,均采用 BY-NC-SA 4.0 许可协议。转载请注明出处!