admin管理员组

文章数量:1252682

I have a local html file with an ajax function trying to pull a xml content from x. 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?

I have a local html file with an ajax function trying to pull a xml content from x.. 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?

Share Improve this question asked Oct 21, 2010 at 14:24 chedinechedine 2,3743 gold badges19 silver badges24 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 8

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 mand line to allow this:

chrome.exe --allow-file-access-from-files

In Mozilla file uri have even stricter same origin policy restrictions.. https://developer.mozilla/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?");
            }
        }

本文标签: javascriptCross domain ajax fails even for a local fileStack Overflow