Amy*_*uGo 116 html javascript google-chrome
我和HERE的情况相同
要解决这个问题,我必须在"--allow-file-access-from-files"模式下使用Chrome启动html文件.我多次尝试后续步骤,但它不起作用.
chrome --allow-file-access-from-files file:///C:/test%20-%203.html
ors*_*zky 103
那面旗子很危险!! 使文件系统保持打开状态以便访问.默认情况下,源自任何地方,本地或Web的文档不应具有对本地file:///资源的任何访问权限.
更好的解决方案是在本地运行一个小的http服务器.
---对于Windows ---
最简单的方法是使用node的包管理器全局安装http-server:
npm install -g http-server
然后只需http-server
在任何项目目录中运行:
例如. d:\my_project> http-server
Starting up http-server, serving ./
Available on:
http:169.254.116.232:8080
http:192.168.88.1:8080
http:192.168.0.7:8080
http:127.0.0.1:8080
Hit CTRL-C to stop the server
Run Code Online (Sandbox Code Playgroud)
或者如prusswan建议的那样,您也可以在Windows下安装Python,并按照以下说明操作.
---对于Linux ---
由于Python通常在大多数Linux发行版中都可用,因此只需python -m SimpleHTTPServer
在项目目录中运行,然后就可以加载页面了http://localhost:8000
在Python 3中,SimpleHTTPServer
模块已合并到http.server
,因此新命令是python3 -m http.server
.
简单,没有安全风险,意外地让您的浏览器易受攻击.
Moh*_*ine 81
搜索Chrome可执行文件的路径,然后在您的cmd上尝试:
> "C:\PathTo\Chrome.exe" --allow-file-access-from-files
Run Code Online (Sandbox Code Playgroud)
编辑: 正如我在你的问题上看到的,不要忘记Windows有点类似于Unix,所以当你输入"chrome ..."时,cmd会在PATH中搜索Chrome,但一般来说Chrome文件夹不是在路径上.此外,您没有为可执行文件指定扩展名...因此,如果您移动到Chrome的文件夹,此命令也可能会起作用:
> .\chrome.exe --allow-file-access-from-files
Run Code Online (Sandbox Code Playgroud)
Gai*_*loe 27
您可能想要尝试使用Web服务器的Web Server,它使用HTTP从本地文件夹提供网页.它使用起来很简单并且可以避免使用标志,正如上面提到的那样,标志可能会使您的文件系统容易受到攻击.
Cla*_*ges 20
在撰写本文时,在OS X中,它通常看起来像这样
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" --allow-file-access-from-files
Run Code Online (Sandbox Code Playgroud)
如果你是一个像我一样的怪人,并把你的应用程序~/Applications
,所以它将是
"/Users/yougohere/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" --allow-file-access-from-files
Run Code Online (Sandbox Code Playgroud)
如果这些都不起作用,请输入chrome://version
您的Chrome地址栏,它会告诉您应该使用的"命令行"调用.只需添加--allow-file-access-from-files
即可.
gma*_*man 15
不要这样做! 你正在打开机器进行攻击.而是运行本地服务器.它就像打开shell /终端/命令行并输入一样简单
cd path/to/files
python -m SimpleHTTPServer
Run Code Online (Sandbox Code Playgroud)
然后将浏览器指向
http://localhost:8000
Run Code Online (Sandbox Code Playgroud)
如果你发现它太慢,请考虑这个解决方案
如果您使用的是mac,则可以使用以下终端命令:
open -a Google\ Chrome --args --allow-file-access-from-files
Run Code Online (Sandbox Code Playgroud)
退出(强制退出)chrome 的所有实例。否则下面的命令将不起作用。
open -a "Google Chrome" --args --allow-file-access-from-files
Run Code Online (Sandbox Code Playgroud)
在终端中执行此命令将打开 Chrome,无论它安装在哪里。
归档时间: |
|
查看次数: |
305901 次 |
最近记录: |