views:

813

answers:

5

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?

+1  A: 

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");
Cleiton
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
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
A: 

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.

TM
A: 

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.

Justin Meyer
Can JSONP work for the file protocol? That's not a rhetorical; I'm actually curious.
Matchu
If your data is at file://mydata.jsonpand it looks like callback = {data: "hello"}you can use JSONP to request that data.
Justin Meyer
A: 

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

lukemabat
A: 

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;
    }
Topera