parent.html : OnClick="popup();"
1. page opens and displays contents
2. but js function isn't working. js function is defined in js file. 3. i checked using firebug, js file loded successfully. 4. it only works after refreshing the page. Any idea please? what am i making mistake? js function :<script>
function popup(){
var test = "<html><head>";
test += "<script src= " + '"'+"jqueryTestfile.js"+'"'+ "> <" + '/' + "script>";
开发者_运维问答 test += "</head><body>";
test += "<div id=" + '"' +"anyId" + '"' + ">";
test += "</div>";
test += "</body></html>";
win.document.write(test);
}
</script>
child pop-up and source code looks like :
<html> <head>
<script src = "jQueryTestFile.js"> </script>
</head> <body> <div id = "anyId">
some content here ...
</div> </body> </html>
I resolved my problem after a no. of attempt and would like to share :
<script type="text/javascript">
window.document.close();
</script>
Why were not js functions working even after downloading the files : because of i was opening (pop up) a new window using window.document.write()
and this method was causing the problem so i used window.document.close()
to force a page to 'finish loading'.
var h = document.getElementsByTagName('head')[0],
s = document.createElement('script');
s.type = 'text/javascript';
s.onload = function () { document.getElementById('hello').innerText = h.innerText; };
s.src = 'http://html5shiv.googlecode.com/svn/trunk/html5.js';
h.appendChild(s);
see: http://jsbin.com/uhoger
精彩评论