views:

29

answers:

2

I have a local html file with an ajax function trying to pull a xml content from x.com. The file when run works only on IE and fails on firefox and safari browsers. Ofcourse this may be because of the Same origin policy. But,I have heard from someone that for scripts loaded using file:// protocol,this same origin policy will not apply. Is it true and if yes, what can be problem with my local html file?

+2  A: 

It is indeed applied to local files, treating them all as separate domains (this varies by browser, as you're seeing). For example in Chrome you can launch it with a command line to allow this:

chrome.exe --allow-file-access-from-files
Nick Craver
+1  A: 

In Mozilla file uri have even stricter same origin policy restrictions.. https://developer.mozilla.org/En/Same-origin_policy_for_file:_URIs However you can over-ride by asking for permission for global access using:

 if (navigator.userAgent.indexOf("Firefox") != -1) {
            try {
                netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
            } 
            catch (e) {
                alert("Permission UniversalBrowserRead denied -- not running Mozilla?");
            }
        }
Sharad