try it
on the index.html page write:
<script type="text/javascript"> function init() { var s = document.createElement("script"); s.innerHTML="alert('ops');" document.getElementById("frame").contentDocument.getElementsByTagName("body")[0].appendChild(s); } window.onload = init; </script>
...
<body> <form id="form1"> <div> <iframe id="frame" src="test.html"></iframe> </div> </form> </body>
Then just write test.html as:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> </head> <body> </body> </html>
and download index.html from the web server and the code works!
source share