简体   繁体   English

尝试停用Chrome同源策略

[英]Trying to disable Chrome same origin policy

I'm trying to follow a melonJS tutorial. 我正在尝试遵循melonJS教程。 It says I should disable cross-origin request using one of two methods: 它说我应该使用以下两种方法之一禁用跨源请求:

--disable-web-security -禁用网络安全

--allow-file-access-from-files** --allow-文件访问从档案**

I've tried both of these in my command prompt as such: 我在命令提示符中尝试了这两个:

C:\Users\danniu>C:\Users\danniu\AppData\Local\Google\Chrome\Application\Chrome.e
xe --allow-file-access-from-files

C:\Users\danniu>C:\Users\danniu\AppData\Local\Google\Chrome\Application\Chrome.e
xe --disable-web-security

When I try to run the game in Chrome I'm still getting this error: 当我尝试在Chrome中运行游戏时,我仍然收到此错误:

XMLHttpRequest cannot load file:///C:/Users/danniu/Desktop/JavaScript/melonJS/data/map/area01.tmx. Cross origin requests are only supported for HTTP.

What am I doing wrong? 我究竟做错了什么?

Thanks 谢谢

You need to use both arguments. 您需要使用这两个参数。 This is how I run it on my mac. 这是我在我的Mac上运行它的方式。

open -a Google\ Chrome --args --disable-web-security -–allow-file-access-from-files

This is how it should be for windows: 这是它应该如何为Windows:

"C:\PathTo\Chrome.exe" –allow-file-access-from-files -disable-web-security

To disable chrome web security on mac use this command on terminal 要在mac上禁用chrome web security,请在终端上使用此命令

$ /Applications/Google\\ Chrome.app/Contents/MacOS/Google\\ Chrome --user-data-dir="/tmp/chrome_dev_session" --disable-web-security $ / Applications / Google \\ Chrome.app/Contents/MacOS/Google \\ Chrome --user-data-dir =“/ tmp / chrome_dev_session”--disable-web-security

if $ open -a Google\\ Chrome --args --disable-web-security -–allow-file-access-from-files dosen't help 如果$ open -a Google \\ Chrome --args --disable-web-security --allow-file-access-from-files不会有帮助

You should request through a HTTP protocol 您应该通过HTTP协议请求

Here's an answer quite simple to do it: https://stackoverflow.com/a/23118676/1585438 这是一个非常简单的答案: https//stackoverflow.com/a/23118676/1585438

The anti-SOP paramters: --disable-web-security -–allow-file-access-from-files 反SOP参数: - --disable-web-security -–allow-file-access-from-files

To make the parameters effective, there must not be another instance of chrome running. 要使参数生效,不得运行另一个chrome实例。 If you have chrome running already and start a new instance with the anti-SOP parameters, it will have no effect. 如果您已经运行了chrome并使用反SOP参数启动新实例,则它将无效。

When you close chrome, make sure that all instances are closed. 关闭镶边时,请确保关闭所有实例。 This includes instances without GUI as well (task manager is your friend)! 这包括没有GUI的实例 (任务管理器是你的朋友)!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM