js 动态修改iframe的src

项目组里有功能需要,当前页面获取url传递过来的参数值,动态赋值给iframe的src,从而实现动态加载iframe的需求,代码如下:


<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,从而实现功能需求!

你可能感兴趣的:(HTML,js修改iframe的src,iframe,src,修改iframe的src)