6

I have a set of HTML files using JavaScript to generate navigation tools, indexing, TOC, etc. These files are only meant to be opened locally (e.g., file://) and not served on a web server. Since Firefox 3.x, we run into the following error when clicking a nav button that would generate a new frame for the TOC:

Error: Permission denied for <file://> to get property Location.href from <file://>.

I understand that this is due to security measures within FF 3.x that were not in 2.x, in that the document.domain does not match, so it's assuming this is cross-site scripting and is denying access.

Is there a way to get around this issue? Perhaps just a switch to turn off/on within Firefox? A bit of JavaScript code to get around it?

5 Answers 5

1

In firefox:

  1. In address bar, type about:config,
  2. then type network.automatic-ntlm-auth.trusted-uris in search bar
  3. Enter comma separated list of servers (i.e., intranet,home,company)

Another way is editing the users.js.

In users.js, write:

user_pref("capability.policy.policynames", "localfilelinks");
user_pref("capability.policy.localfilelinks.sites", "http://site1.com http://site2.com");
user_pref("capability.policy.localfilelinks.checkloaduri.enabled", "allAccess");

But if you want to stop all verification, just Write the following line into users.js file:

user_pref("capability.policy.default.checkloaduri.enabled", "allAccess");
3
  • That seems to be what you'd do for files served on servers, but what of those I'm accessing via file:// where there's no domain?
    – Gudlyf
    Aug 17, 2009 at 20:21
  • This solution is for cases where you have a website (hosted in somewhere) and it needs to read some files in client's hard-drive. Another solution is turn off this policy(I edited my answer with how to do that) - I holpe you understand :)
    – Cleiton
    Aug 17, 2009 at 21:21
  • This isn't working for me under Firefox 11. I've used user.js in the correct profile directory and I've tried directly entering it from about:config. URL is "http:// localhost".
    – Michael
    Apr 22, 2012 at 17:42
1

You may use this in firefox to read the file.

function readFile(arq) {
        netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
        var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
        file.initWithPath(arq);

        // open an input stream from file  
        var istream = Components.classes["@mozilla.org/network/file-input-stream;1"].createInstance(Components.interfaces.nsIFileInputStream);
        istream.init(file, 0x01, 0444, 0);
        istream.QueryInterface(Components.interfaces.nsILineInputStream);  
        var line = {}, lines = [], hasmore;  
        do {  
          hasmore = istream.readLine(line);  
          lines.push(line.value);   
        } while(hasmore);  
        istream.close();  
        return lines;
    }
0

Cleiton's method will work for yourself, or for any users who you expect will go through this manual process (not likely unless this is a tool for you and your coworkers or something).

I'd hope that this type of thing would not be possible, because if it is, that means that any site out there could start opening up documents on my machine and reading their contents.

0

You can have all files that you want to access in subfolders relative to the page that is doing the request.

You can also use JSONP to load files from anywhere.

2
  • Can JSONP work for the file protocol? That's not a rhetorical; I'm actually curious.
    – Matchu
    Aug 22, 2009 at 13:15
  • If your data is at file://mydata.jsonp and it looks like callback = {data: "hello"} you can use JSONP to request that data. Aug 22, 2009 at 19:51
-1

Add "file://" to network.automatic-ntlm-auth.trusted-uris in about:config

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.