Html 如何在“--allow-file-access-from-files”模式下使用Chrome启动html?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18586921/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to launch html using Chrome at "--allow-file-access-from-files" mode?
提问by AmyWuGo
I have the same situation with HERE
我和这里有同样的情况
And to solve this problem I have to launch html file using Chrome at "--allow-file-access-from-files" mode. I tried next steps many times, but it doesn't work.
为了解决这个问题,我必须在“--allow-file-access-from-files”模式下使用 Chrome 启动 html 文件。我尝试了很多次下一步,但它不起作用。
- start cmd under windows 7
- direct to chrome.exe folder
- do this
chrome --allow-file-access-from-files file:///C:/test%20-%203.html
- 在windows 7下启动cmd
- 直接到 chrome.exe 文件夹
- 做这个
chrome --allow-file-access-from-files file:///C:/test%20-%203.html
采纳答案by Mohamed Amine
Search for the path of your Chrome executable and then, on your cmd, try :
搜索您的 Chrome 可执行文件的路径,然后在您的 cmd 上尝试:
> "C:\PathTo\Chrome.exe" --allow-file-access-from-files
EDIT :As I see on your question, don't forget that Windows is a little bit similar to Unix, so when you type "chrome ...", cmd will search for Chrome in the PATH, but in general the Chrome folder isn't on the PATH. Also, you don't specify an extension for your executable... So if you move to Chrome's folder, this command will probably work too :
编辑:正如我在你的问题中看到的,不要忘记 Windows 有点类似于 Unix,所以当你输入“chrome ...”时,cmd 将在 PATH 中搜索 Chrome,但通常 Chrome 文件夹不是不在 PATH 上。此外,您没有为可执行文件指定扩展名...因此,如果您移动到 Chrome 的文件夹,此命令也可能会起作用:
> .\chrome.exe --allow-file-access-from-files
回答by orszaczky
That flag is dangerous!!Leaves your file system open for access. Documents originating from anywhere, local or web, should not, by default, have any access to local file:/// resources.
那个旗帜很危险!!使您的文件系统保持开放以供访问。默认情况下,源自任何地方、本地或 Web 的文档不应访问本地 file:/// 资源。
Much better solution is to run a little http server locally.
更好的解决方案是在本地运行一个小的 http 服务器。
--- For Windows ---
--- 对于 Windows ---
The easiest is to install http-server globally using node's package manager:
最简单的方法是使用 node 的包管理器全局安装 http-server:
npm install -g http-server
npm install -g http-server
Then simply run http-server
in any of your project directories:
然后只需http-server
在您的任何项目目录中运行:
Eg. d:\my_project> 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
Or as prusswan suggested, you can also install Python under windows, and follow the instructions below.
或者按照 prusswan 的建议,你也可以在 windows 下安装 Python,然后按照下面的说明进行操作。
--- For Linux ---
--- 对于 Linux ---
Since Python is usually available in most linux distributions, just run python -m SimpleHTTPServer
in your project directory, and you can load your page on http://localhost:8000
由于 Python 通常在大多数 linux 发行版中可用,只需python -m SimpleHTTPServer
在您的项目目录中运行,您就可以在http://localhost:8000
In Python 3 the SimpleHTTPServer
module has been merged into http.server
, so the new command is python3 -m http.server
.
在 Python 3 中,该SimpleHTTPServer
模块已合并到 中http.server
,因此新命令是python3 -m http.server
.
Easy, and no security risk of accidentally leaving your browser open vulnerable.
简单,并且没有意外让您的浏览器打开易受攻击的安全风险。
回答by Gail Parsloe
You may want to try Web Server for Chrome, which serves web pages from a local folder using HTTP. It's simple to use and would avoid the flag, which, as someone mentioned above, might make your file system vulnerable.
您可能想尝试Web Server for Chrome,它使用 HTTP 从本地文件夹提供网页。它使用起来很简单,并且可以避免使用标志,正如上面提到的那样,这可能会使您的文件系统容易受到攻击。
回答by Clay Bridges
As of this writing, in OS X, it will usually look like this
在撰写本文时,在 OS X 中,它通常看起来像这样
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" --allow-file-access-from-files
If you are a freak like me, and put your apps in ~/Applications
, then it will be
如果你像我一样是个怪胎,把你的应用程序放进去~/Applications
,那么它会是
"/Users/yougohere/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" --allow-file-access-from-files
If neither of those are working, then type chrome://version
in your Chrome address bar, and it will tell you what "command line" invocation you should be using. Just add --allow-file-access-from-files
to that.
如果这些都不起作用,那么chrome://version
在你的 Chrome 地址栏中输入,它会告诉你应该使用什么“命令行”调用。只是补充--allow-file-access-from-files
一下。
回答by gman
Don't do this!You're opening your machine to attacks. Instead run a local server. It's as easy as opening a shell/terminal/commandline and typing
不要这样做!你正在打开你的机器进行攻击。而是运行本地服务器。就像打开 shell/终端/命令行并输入一样简单
cd path/to/files
python -m SimpleHTTPServer
Then pointing your browser to
然后将浏览器指向
http://localhost:8000
If you find it's too slow consider this solution
如果您发现它太慢,请考虑此解决方案
回答by taz
If you are using a mac you can use the following terminal command:
如果您使用的是 mac,您可以使用以下终端命令:
open -a Google\ Chrome --args --allow-file-access-from-files
回答by Matt Perejda
Quit (force quit) all instances of chrome. Otherwise the below command will not work.
退出(强制退出)所有 chrome 实例。否则下面的命令将不起作用。
open -a "Google Chrome" --args --allow-file-access-from-files
Executing this command in terminal will open Chrome regardless of where it is installed.
无论安装在哪里,在终端中执行此命令都会打开 Chrome。
回答by Bonn
On windows:
在窗户上:
chrome --allow-file-access-from-files file:///C:/test%20-%203.html
On linux:
在 Linux 上:
google-chrome --allow-file-access-from-files file:///C:/test%20-%203.html
回答by Yogesh Jog
REM Kill all existing instance of chrome
taskkill /F /IM chrome.exe /T
REM directory path where chrome.exe is located
set chromeLocation="C:\Program Files (x86)\Google\Chrome\Application"
cd %chromeLocation%
cd c:
start chrome.exe --allow-file-access-from-files
save above lines as .batfile
将以上行另存为.bat文件
回答by jo0gbe4bstjb
Depending on the file which will be put into filesystem, as long as that file is not a malware, then that would be safe.
取决于将放入文件系统的文件,只要该文件不是恶意软件,那就是安全的。
But don't worry to write/read file(s) to File System directory, cause you can tighten that directory security (include it's inheritance) by give a proper access right and security restriction. eg: read/write/modify.
但是不要担心向文件系统目录写入/读取文件,因为您可以通过提供适当的访问权限和安全限制来加强该目录的安全性(包括它的继承)。例如:读/写/修改。
By default, File System, Local Storage, and Storage directory are located on "\Users[Current User]\AppData\Local\Google\Chrome\User Data\Default" directory.
默认情况下,文件系统、本地存储和存储目录位于“\Users[当前用户]\AppData\Local\Google\Chrome\User Data\Default”目录中。
However you can customize it by using "--user-data-dir" flag.
但是,您可以使用“--user-data-dir”标志对其进行自定义。
And this is a sample:
这是一个示例:
"C:\Program Files (x86)\Google\Application\chrome.exe" --user-data-dir="C:\Chrome_Data\OO7" --allow-file-access-from-files
Hope this helps anyone.
希望这可以帮助任何人。