windows 如何在 Microsoft Edge 浏览器中打开本地 HTML 文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34798285/
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 can I open a local HTML file in Microsoft Edge browser?
提问by Warren P
Since time immemorial, most web browsers have been able to open a local file if you ran the web-browser executable, for example just execute iexplore.exe file:/c:/temp/file
or via the IShellDocView
interfaces. I am trying to do this from within my own program, in Windows 10, with Microsoft Edge, and am unaware of how to do it.
自远古时代以来,如果您运行 Web 浏览器可执行文件,大多数 Web 浏览器都能够打开本地文件,例如仅执行iexplore.exe file:/c:/temp/file
或通过IShellDocView
接口。我正在尝试在我自己的程序中使用 Microsoft Edge 在 Windows 10 中执行此操作,但我不知道如何执行此操作。
The executable appears to be completely undocumented, does not respond to /? or /help, and simply crashes no matter what I pass to it, and given that the path appears to be likely to change, is probably not the correct approach to invoke this executable directly:
可执行文件似乎完全没有记录,不响应 /? 或 /help,无论我传递给它什么,它都会崩溃,并且鉴于路径似乎可能会改变,这可能不是直接调用此可执行文件的正确方法:
C:\Windows\SystemApps\Microsoft.MicrosoftEdge_8wekyb3d8bbwe\MicrosoftEdge.exe <whatever>
Is there an API in Windows that can be invoked instead, that will open Edge, perhaps even if it is not the current default browser?
Windows 中是否有可以调用的 API,它会打开 Edge,即使它不是当前的默认浏览器?
If it was the default browser, I believe I could just do what I want via Win32 shell-API ShellExecute
. I would like to be able to launch something in Edge even if I have set another browser as my default though, for the purpose of automating certain web-testing tasks.
如果它是默认浏览器,我相信我可以通过 Win32 shell-API 做我想做的事ShellExecute
。即使我将另一个浏览器设置为默认浏览器,我也希望能够在 Edge 中启动某些内容,以实现某些 Web 测试任务的自动化。
Are there programmatic interfaces or APIs for Edge? For purposes of this question, let's say I want to write this in C, but this should be the same API no matter what language I'm using so I didn't tag this question C.
Edge 是否有编程接口或 API?出于这个问题的目的,假设我想用 C 编写它,但是无论我使用什么语言,这都应该是相同的 API,所以我没有将这个问题标记为 C。
If there is no way to do it programmatically, is there a command line argument I could use and pass to a MicrosoftEdge or MicrosoftEdgeCP executable?
如果无法以编程方式执行此操作,是否可以使用命令行参数并将其传递给 MicrosoftEdge 或 MicrosoftEdgeCP 可执行文件?
回答by Sampson
This is currently not supported, but the team is evaluating it as an option. For the time being, the easiest way to open a resource in Edge is by using the microsoft-edge:
protocol handler. For instance, you could run microsoft-edge:http://stackoverflow.comto open Stack Overflow in Edge.
目前不支持此功能,但团队正在将其作为一个选项进行评估。目前,在 Edge 中打开资源的最简单方法是使用microsoft-edge:
协议处理程序。例如,您可以运行microsoft-edge:http://stackoverflow.com 在 Edge 中打开 Stack Overflow。
回答by TempGuest
Here is how you can open a PDF for example, with Edge.
例如,以下是使用 Edge 打开 PDF 的方法。
Add the following header at the top of your class:
在类的顶部添加以下标题:
[DllImport("Shell32.dll")]
public static extern int ShellExecuteA(IntPtr hwnd, string lpOperation, string lpFile, string lpParameters, string lpDirecotry, int nShowCmd);
Here is an example of how to make the call.
以下是如何拨打电话的示例。
ShellExecuteA(System.IntPtr.Zero, "open", @"shell:Appsfolder\Microsoft.MicrosoftEdge_8wekyb3d8bbwe!MicrosoftEdge", "C:\MyFile.pdf", null, 10);
I think this will apply fine to other types of files as well.
我认为这也适用于其他类型的文件。
回答by Augie Mattheiss
This works on my system:
这适用于我的系统:
create a share and give yourself access
创建共享并授予自己访问权限
open in Microsoft Edge, as a simple example: file:////bookmark.html
在 Microsoft Edge 中打开,举个简单的例子:file:////bookmark.html
you can get the hostname via the hostname Powershell command among other ways, you can see all the directories you are sharing by using file explorer, opening "network", at your computer and you should see any shares you have established
您可以通过 hostname Powershell 命令以及其他方式获取主机名,您可以通过使用文件资源管理器在您的计算机上打开“网络”来查看您共享的所有目录,您应该会看到您建立的任何共享
not necessarily a deeply satisfying answer but works for what I needed.
不一定是一个非常令人满意的答案,但可以满足我的需要。
回答by Herschelle42
Obtain tool from https://github.com/MicrosoftEdge/edge-launcher
从https://github.com/MicrosoftEdge/edge-launcher获取工具
MicrosoftEdgeLauncher file:///C:/Users/me/Documents/homepage.html
MicrosoftEdgeLauncher file:///C:/Users/me/Documents/homepage.html
回答by Martin Schneider
The following works for local files and also accepts queries (?
) and fragments (#
) in the URI.
以下内容适用于本地文件,并且还接受URI 中的查询 ( ?
) 和片段 ( #
)。
WinAPI / ShellAPI example on a local HTML file:
本地 HTML 文件上的 WinAPI / ShellAPI 示例:
ShellExecute(
NULL,
NULL,
_T("shell:Appsfolder\Microsoft.MicrosoftEdge_8wekyb3d8bbwe!MicrosoftEdge"),
_T("file:///c:/temp/test.html?page=1#anchor-1"),
NULL,
SW_SHOWNORMAL);
回答by kevinf
Microsoft introduced App Aliases, if you check your AppData folder, which is included in Windows path automatically, you will find MicrosoftEdge.exe
微软引入了App Aliases,如果你检查你的AppData文件夹,它自动包含在Windows路径中,你会发现MicrosoftEdge.exe
Directory of C:\Users\username\AppData\Local\Microsoft\WindowsApps
06/25/2019 04:13 PM <DIR> Backup
10/08/2019 03:35 PM 0 dbgsrv32.exe
10/08/2019 03:35 PM 0 dbgsrv64.exe
11/07/2019 01:40 PM <DIR> Microsoft.MicrosoftEdge_8wekyb3d8bbwe
10/08/2019 03:35 PM <DIR> Microsoft.WinDbg_8wekyb3d8bbwe
11/07/2019 01:40 PM 0 MicrosoftEdge.exe
10/08/2019 03:35 PM 0 WinDbgX.exe
4 File(s) 0 bytes
3 Dir(s) 119,020,060,672 bytes free
Unfortunately the alias does not appear to open HTML files or response to any CLI, unlike the working WinDbgX.
不幸的是,别名似乎不会打开 HTML 文件或响应任何 CLI,这与工作的 WinDbgX 不同。
So once Microsoft implements shell CLI for Edge, that will be the correct invocation method.
因此,一旦 Microsoft 为 Edge 实现 shell CLI,这将是正确的调用方法。
One workaround, is to type in the URL bar, a file:// URI like the following (note: /is needed):
一种解决方法是在 URL 栏中键入 file:// URI,如下所示(注意:/是必需的):
file:///D:/random/path/file.html