js 动态修改iframe的src
项目组里有功能需要,当前页面获取url传递过来的参数值,动态赋值给iframe的src,从而实现动态加载iframe的需求,代码如下:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><title>打印</title><meta htt
·
项目组里有功能需要,当前页面获取url传递过来的参数值,动态赋值给iframe的src,从而实现动态加载iframe的需求,代码如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>打印</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script>
function parseQueryString (url) {
var result = {};
var str = url.split("?")[1];
if (str == undefined)
return result;
var items = str.split("&")
var arr;
for (var i = 0; i < items.length; i++) {
arr = items[i].split("=");
result[arr[0]] = arr[1];
}
return result;
};
function cc(){
var params = parseQueryString(window.location.href);
var orderId = params.orderId;
document.getElementById("reportFrame").src = "http://172.21.24.111/webroot/decision/view/report?viewlet=AM-Dept%252Fqitafangshiqude.cpt&orderId="+orderId;
}
</script>
</head>
<body onload="cc();">
<iframe id="reportFrame" width="100%" height="100%" src=""></iframe>
</body>
</html>
备注:页面获取url传递过来的url,页面加载完成后,控制iframe的src,从而实现功能需求!
更多推荐
已为社区贡献1条内容
所有评论(0)