Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Chrome Won't Accept .contentDocument or .contentWindow

When I try my code out:

Testing.html -

<script language="JavaScript" type="text/javascript">
function find() { 
var iframeEl = document.getElementById('love');
if ( iframeEl.contentDocument ) {
    var form = iframeEl.contentDocument.document.getElementById('hi').getAttribute('href');
    alert(form)
} else if ( iframeEl.contentWindow ) {
    var form = iframeEl.contentWindow.document.getElementById('hi').getAttribute('href');
    alert(form)
} 
  }
</script>
<body onload="find()">
<iframe name="lovez" src="frame.html" id="love"><a href="http://www.google.com" id="hi">Testingz</a></iframe>
</body>

Frame.html -

<a href="http://www.google.com" id="hi">Testing</a>

It will not return an alert box. However on Internet Explorer it will. I have been searching the internet, trying all examples and can't find a simple example that will work in Google Chrome. Am I doing something wrong or is it just Google Chrome?

like image 582
jhfire Avatar asked Oct 30 '25 16:10

jhfire


1 Answers

I've noticed that both the contentDocument and getSVGDocument (for svg objects from svg files) will work fine if the code is from a web server, but when I copy the code to a local file, it will not work.

Here's a sample link with a code I coppied from which works on the web but not from my disk.

Here's the solution I just found from Chrome (thanks to Artem S), i.e. using the --allow-file-access-from-files flag.

like image 73
Israel Gav Avatar answered Nov 01 '25 06:11

Israel Gav