Javascript Iframe Without Src With Nested Scripts
Is it possible to create an iframe with scripts in its head element, before the iframe being inserted into the dom and have the scripts onload='alert(1)' fire when they are ready?
Solution 1:
Try this:
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
function insertIframe() {
var iframe = $('<iframe></iframe>').appendTo('body')[0];
// switch to straight JS
var script = iframe.contentWindow.document.createElement("script");
script.type = "text/javascript";
script.src = "//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js";
script.onload = function() { alert(1); };
iframe.contentWindow.document.body.appendChild(script);
}
</script>
</head>
<body onload="insertIframe()">
</body>
Post a Comment for "Javascript Iframe Without Src With Nested Scripts"