3

I've been trying to edit some pages as local htm files on my computer, but I've run into this problem where functions using the contentWindow property don't work when the parent page and the page within the iframe are local files. When all the pages are uploaded the exact same codes work fine, but not as local files. It's only in Chrome and Opera that I've had this problem. In Firefox and Safari and even Internet Explorer contentWindow works fine with local files.

This is very annoying because I've got a dynamic iframe resize in the page I'm working on and I don't want to have to reupload all the pages every time I want to test them in Chrome which is my main browser.

Is there some sort of security setting in Chrome (and Opera) that's causing this problem, and if so can it be disabled?

The code is just:

function resizeIframe(iframeName) {

   document.getElementById(iframeName).style.height = '1000px';

   newHeight = document.getElementById(iframeName).contentWindow.document.body.scrollHeight;

   setTimeout(function () {
        document.getElementById(iframeName).style.height = newHeight + 'px';
   }, 10);
}
user2856593
  • 97
  • 3
  • 11

1 Answers1

1

As it turns out, it is a security thing, but there's no way to simply turn it off from the settings menu. The only way (so far as I've found) to turn it off (in windows) is to open Chrome from the command prompt window by typing the file path and adding --allow-file-access-from-files to the command line. This also works for Opera.

Unfortunately this doesn't turn it off permanently so you have to open the browser this way every time you want to test a page that uses the contentWindow property. This works out okay when I'm using Chrome because I keep it open on my computer all the time anyway, but it's a little annoying when I want to test something in Opera. Maybe somebody else will post a way of making it permanent, but for now this will have to do.

Sources:

Is it likely that future releases of Chrome support contentWindow/contentDocument when iFrame loads a local html file from local html file?

http://www.chrome-allow-file-access-from-file.com/

Community
  • 1
  • 1
user2856593
  • 97
  • 3
  • 11