Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I open a local HTML file in Microsoft Edge browser?

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.

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:

  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?

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.

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.

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?

like image 934
Warren P Avatar asked Jan 14 '16 19:01

Warren P


People also ask

How do I run a HTML file in Microsoft Edge?

Locate your html file in file explorer and right click on it > open with > select microsoft edge. Your html will be now open on microsoft edge. You can also set default apps for html files, go to your system settings and search for default apps and select microsoft edge and then in next page for .

How do I open an HTM file in Edge browser?

Hi, use File explorer to launch a local html file in the browser of your choice, by right clicking on the local html file and selecting the 'Open with' context menu.


2 Answers

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.com to open Stack Overflow in Edge.

like image 52
Sampson Avatar answered Oct 03 '22 06:10

Sampson


Here is how you can open a PDF for example, with Edge.

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.

like image 37
TempGuest Avatar answered Oct 03 '22 06:10

TempGuest