title: Call a JavaScript function defined in an iframe in Chrome using the file protocol
body: <p>This question is extremely similar to the fully-updated version of the question asked here: <a href="https://stackoverflow.com/questions/2570718/how-to-call-a-javascript-function-from-one-frame-to-another-in-chrome-webkit-with">How to call a JavaScript function from one frame to another in Chrome/Webkit with file protocol</a> &mdash; unfortunately, that question was never actually answered.</p>
  
  <p>I have an HTML page that contains an SVG image in an iframe. The SVG exports a JavaScript API that allows it to do useful things (reset to zoomed and centered, display at "actual size"). Below the iframe, I've put buttons that the user can click on that call through to the functions defined in the SVG. </p>
  
  <p>My code looks like this:</p>
  
  <pre><code>function reset() {
    document.getElementByID('iframe').contentWindow.reset();
  }
  </code></pre>
  
  <p>It works perfectly in Safari, Firefox, and even IE 9 (which supports SVGs - hooray!). But on Chrome, it fails: the debugger informs me that:</p>
  
  <p><code>Property 'reset' of object [object DOMWindow] is not a function</code>.</p>
  
  <p>And indeed, there does seem to be truth to that: even though 'contentWindow' is of type DOMWindow, it has no methods or fields (at least, not that the debugger will show me). Even asking for its 'document' field fails (yields null).</p>
  
  <p>The rub appears to be the use of the file:// protocol to transfer both the containing HTML and the contained SVG. As noted in the question I referenced above, Chrome produces the following error when the attempt to access 'contentWindow' is made:</p>
  
  <p><code>Attempt to access frame with URL file://[...]/contained.svg from frame with URL file://[...]/container.html. Domains, protocols and ports must match.</code></p>
  
  <p>In general, I think security is great; this looks like a security-inspired restriction. But here, it seems to have gone too far: these are files on the user's filesystem, after all, and in my case, are even in the same directory. </p>
  
  <p>Hosting the code is not an option - it must reside on the user's machine. I'd hate to have to tell people "just don't use Chrome - it has silly notions of security." </p>
  
  <p>Is there no way to work around this restriction?</p>