js dynamically modify the src of the iframe

There are functional needs in the project group. The current page gets the parameter values ​​passed by the url and dynamically assigns them to the src of the iframe, thus realizing the requirement of dynamically loading the iframe. The code is as follows:

<!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>

Remarks: The page gets the url passed by the url. After the page is loaded, it controls the src of the iframe to meet the functional requirements!

Guess you like

Origin blog.csdn.net/wujian_csdn_csdn/article/details/108094668