在一个页面index.html中,使用到了iframe <iframe name="iFrame" allowtransparency="true" src="/aaa/bbb.html?name="tom"&sex="male" width="100%" height="100%" id="student" style="border: none;">这个iframe引入了另一个页面bbb.html,并且传入了两个参数name和sex但是在bbb.html页面中如何获得这两个参数呢?我在页面中一直是undefined?
1 回答

烙印99
TA贡献1829条经验 获得超13个赞
方法如下:
//获取URL中参数
function getUrlParam(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
var r = window.location.search.substr(1).match(reg); //匹配目标参数
if (r != null) return unescape(r[2]);//返回参数值
return null;
}
以你的页面为例:
在bbb.html页面中,调用getUrlParam('name')和getUrlParam('sex')即可
添加回答
举报
0/150
提交
取消