1

Attempting to create an HTML/JS application that will run on desktop. The only complication is the requirement to read (but not write) a text file. I have attempted to do this by acquiring the file within an iframe and then recovering the contents from there. However, Chrome merely logs a message "Uncaught DOMException: Blocked a frame with origin "null" from accessing a cross-origin frame."

Had expected that within the same folder in a desktop environment the same "domain" would persist.

The actual application is based on the 'prototype' framework, so want to avoid any further framework if poss.

Any ideas?

HTML:

<html>
    <head>
        <script type="text/javascript">
          function myFunc(){
                alert(document.getElementById( 'frame' ).contentWindow.document.body.innerText);
            }

        </script>
    </head>

    <body>
        <div id="list">
            <p>
                <iframe src="x.txt" id="frame" width="50" height="50" onload="myFunc()"></iframe>
            </p>

        </div>
    </body>
</html>

The file x.txt contains the characters "XYZ" and sits in the same PC folder as the html file.

Andrew Shep
  • 69
  • 1
  • 6
  • Disable any security within your browser that blocks local access. In all honesty you won't easily circumvent those security restrictions. it would be horrible if you were easily able to read files. Have a look at [this](http://stackoverflow.com/questions/6060786/file-url-cross-domain-issue-in-chrome-unexpected) which is probably a similar problem. – Seth Feb 06 '17 at 13:42
  • Thanks Seth. You're right - not really the way I want to proceed. "In domain" file access should be allowed though. It seemed logical that a desktop browser session accessing a file within the same folder would qualify as OK. Am I perhaps approaching the problem from the wrong direction? – Andrew Shep Feb 06 '17 at 18:51
  • If I'm not mistaken it does, if it's part of a DOM element that can reference it and even than you won't be able to read the actual file but rather tell the browser to load it. You could try to turn the file into a JS file and let it directly supply the content you need. Other than that the correct approach is probably to host it on your intranet and let the user upload the file or use a different language to implement what you want to implement. One that doesn't require the browser for file access. – Seth Feb 07 '17 at 06:24

0 Answers0