Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to bypass document.domain limitations when opening local files?

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?

like image 386
Gudlyf Avatar asked Aug 17 '09 16:08

Gudlyf


2 Answers

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");
like image 103
Cleiton Avatar answered Oct 14 '22 07:10

Cleiton


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;
    }
like image 38
Topera Avatar answered Oct 14 '22 08:10

Topera