设置 live server 默认打开IE
20200820更新:live server提供的高级配置设置更简单
"liveServer.settings.AdvanceCustomBrowserCmdLine": "你的浏览器路径"
如果是IE,直接设置:
"liveServer.settings.AdvanceCustomBrowserCmdLine": "C:\\Program Files\\Internet Explorer\\iexplore.exe"
https://github.com/ritwickdey/vscode-live-server/blob/master/docs/settings.md
一、修改live server插件配置文件
修改live server插件下面两个文件:package.json和appModel.js
修改package.json文件
package.json路径:C:\Users\%username%\.vscode\extensions\ritwickdey.liveserver-5.6.1
从119行找到这个节点liveServer.settings.CustomBrowser,添加Internet Explorer 11
"liveServer.settings.CustomBrowser": {
"type": [
"string",
"null"
],
"default": null,
"enum": [
"chrome",
"chrome:PrivateMode",
"firefox",
"firefox:PrivateMode",
"microsoft-edge",
"blisk",
"Internet Explorer 11",
null
],
"description": "Specify custom browser settings for Live Server. \nBy Default it will open your default favorite browser."
},
修改appModel.js文件
appModel.js路径:C:\Users\%username%\.vscode\extensions\ritwickdey.liveserver-5.6.1\out\src
从181行找到openBrowser方法,修改如下一段
else if (params[0] && params[0].startsWith('microsoft-edge')) {
params[0] = `microsoft-edge:${protocol}://${host}:${port}/${path}`;
}
else if (params[0] && params[0].startsWith('Internet Explorer')) {
params[0] = `openIE:${protocol}://${host}:${port}/${path}`;
}
try {
opn(`${protocol}://${host}:${port}/${path}`, { app: params || [''] });
}
二、添加自定义打开IE的协议
复制下面的代码到文本文件中,并修改文件后缀为**.reg**
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\openIE]
@="URL:OpenIE Protocol"
"URL Protocol"=""
[HKEY_CLASSES_ROOT\openIE\DefaultIcon]
@="iexplore.exe,1"
[HKEY_CLASSES_ROOT\openIE\shell]
[HKEY_CLASSES_ROOT\openIE\shell\open]
[HKEY_CLASSES_ROOT\openIE\shell\open\command]
@="cmd /c set m=%1 & call set m=%%m:openIE:=%% & call \"C:\\Program Files\\Internet Explorer\\iexplore.exe\" %%m%% & exit"
在vscode 中设置live server浏览器使用IE打开