Disable same origin policy in Chrome
Is there any way to disable the Same-origin policy on Google's Chrome browser?
This is strictly for development, not production use.
Close chrome (or chromium) and restart with the --disable-web-security
argument. I just tested this and verified that I can access the contents of an iframe with src="http://google.com" embedded in a page served from "localhost" (tested under chromium 5 / ubuntu). For me the exact command was:
Note : Kill all chrome instances before running command
chromium-browser --disable-web-security --user-data-dir
The browser will warn you that "you are using an unsupported command line" when it first opens, which you can ignore.
From the chromium source:
// Don't enforce the same-origin policy. (Used by people testing their sites.)
const wchar_t kDisableWebSecurity[] = L"disable-web-security";
Before Chrome 48, you could just use:
chromium-browser --disable-web-security
Yep. For OSX, open Terminal and run:
$ open -a Google Chrome --args --disable-web-security --user-data-dir
--user-data-dir required on Chrome 49+ on OSX
For Linux run:
$ google-chrome --disable-web-security
Also if you're trying to access local files for dev purposes like AJAX or JSON, you can use this flag too.
-–allow-file-access-from-files
For Windows go into the command prompt and go into the folder where Chrome.exe is and type
chrome.exe --disable-web-security
That should disable the same origin policy and allow you to access local files.
Update: For Chrome 22+ you will be presented with an error message that says:
You are using an unsupported command-line flag: --disable-web-security. Stability and security will suffer.
However you can just ignore that message while developing.
For Windows users:
The problem with the solution accepted here, in my opinion is that if you already have Chrome open and try to run this it won't work.
However, when researching this, I came across a post on Super User, Is it possible to run Chrome with and without web security at the same time?.
Basically, by running the following command (or creating a shortcut with it and opening Chrome through that)
chrome.exe --user-data-dir="C:/Chrome dev session" --disable-web-security
you can open a new "unsecure" instance of Chrome at the same time as you keep your other "secure" browser instances open and working as normal.
链接地址: http://www.djcxy.com/p/20464.html下一篇: 在Chrome中停用相同的原产地政策