I have a page which contains 4 Iframe, and all the pages add the same javascript. When the page loaded, I found the same javascript loaded from server 5 times. And then I set all Iframes loads when the javascript is loaded in the parent page, but get the same results, WHY?
The Code of the parent page:
<html> <head> </head> <body> <iframe></iframe> <iframe></iframe> <iframe></iframe> <iframe></iframe> </body> <script> var newScript = document.createElement("script"); newScript.src = "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.1/jquery.min.js"; var srcs = ["html1.html", "html2.html", "html3.html", "html4.html"]; document.getElementsByTagName("HEAD").item(0).appendChild(newScript); newScript.onload = newScript.onreadystatechange = function () { console.log("jquery.min.js loaded"); var iframes = document.getElementsByTagName("iframe"); for (var i = 0; i < iframes.length; i++) { var id = i; iframes[id].src = srcs[id]; } } console.log("init"); </script> </html>
The code in all iframe page:
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=8"> <meta http-equiv="Expires" content="0"> <meta http-equiv="Pragma" content="no-cache"> <meta http-equiv="Cache-control" content="no-cache"> <meta http-equiv="Cache" content="no-cache"> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> </head> <body> html1 </body> </html>
Image: Network of DevTool: