开发者

Cross domain ajax fails even for a local file

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? 开发者_开发问答


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


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?");
            }
        }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜