How to get around document.domain restrictions when opening local files?

I have a set of HTML files using JavaScript to create navigation, indexing, TOC, etc. These files are intended only for local opening (for example, file: //) and are not served on the web server. Starting with Firefox 3.x, we run the following error when the nav button is pressed, which generates 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 inside FF 3.x that were not in 2.x, because document.domain does not match, so it assumes that this is cross-site scripting and denies access.

Is there a way around this problem? Perhaps just a switch to turn on / off in Firefox? Some JavaScript code to get around it?

+6
javascript html firefox
source share
5 answers

In firefox:

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

Another way is editing 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 checks, just write the following line in the users.js file:

 user_pref("capability.policy.default.checkloaduri.enabled", "allAccess"); 
+1
source share

You can use this in firefox to read a 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; } 
+1
source share

The Cleiton method will work for you or for any users that you expect, this manual process will go through (it is unlikely if this is not a tool for you and your employees or something like that).

I hope that this type of thing will not , because if it is, it means that any site there can start opening documents on my machine and read their contents.

0
source share

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

You can also use JSONP to download files from anywhere.

0
source share

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

-one
source share

All Articles