What Browsers Allow Cross-Origin XMLHttpRequest Fr

2019-07-23 20:27发布

问题:

I know Internet Explorer 8 allows cross-domain XHR from LOCAL files, but what about other browsers? I'd like to know about what versions/OS this will work on (if any) for each of the major 5 browsers. Please include any workarounds like Chrome's --disable-web-security flag.

Thanks!

回答1:

well here is a nice blog abt cross domain requests: http://caffeinelab.net/2011/02/08/cross-domain-requests-state-of-the-browsers/

IE provides access control to do cross-domain requests. Now the bad news: as usual, IE can’t do like the others and they have their own non-standard way to provide it.

Instead of a regular XMLHttpRequest, you need to do a XDomainRequest! Moreover, it works only for public pages, not for authenticated pages. So if you need to send he cookies and you want your application to work in IE, you’re pretty much screwed.

and here is how you do it in FFX: http://dirolf.com/2007/06/enabling-cross-domain-ajax-in-firefox.html

Not sure about safari, but Chrome has a command line switch for this:

chrome.exe --disable-web-security

Keep in mind when you enable this you are risking your security when you visit other sites. so be careful

hope this helps



回答2:

In Safari you can enable the Develop menu (Safari → Preferences → Advanced → Show Develop menu in menu bar). There you can disable cross-origin restrictions (Develop → Disable Cross-Origin Restrictions).