如何使用新的Microsoft Visual Studio code在浏览器中查看我的HTML代码?
使用notepad++,您可以选择在浏览器中运行。我如何用Visual Studio Code做同样的事情?
如何使用新的Microsoft Visual Studio code在浏览器中查看我的HTML代码?
使用notepad++,您可以选择在浏览器中运行。我如何用Visual Studio Code做同样的事情?
当前回答
以下在windows 10 ->的1.53.2版本中运行
在终端菜单中选择运行活动文件 它在默认的边缘浏览器中执行html文件
其他回答
Windows -打开默认浏览器-在VS Code v 1.1.0上测试
回答既打开一个特定的文件(名称是硬编码)或打开任何其他文件。
步骤:
Use ctrl + shift + p (or F1) to open the Command Palette. Type in Tasks: Configure Task or on older versions Configure Task Runner. Selecting it will open the tasks.json file. Delete the script displayed and replace it by the following: { "version": "0.1.0", "command": "explorer", "windows": { "command": "explorer.exe" }, "args": ["test.html"] } Remember to change the "args" section of the tasks.json file to the name of your file. This will always open that specific file when you hit F5. You may also set the this to open whichever file you have open at the time by using ["${file}"] as the value for "args". Note that the $ goes outside the {...}, so ["{$file}"] is incorrect. Save the file. Switch back to your html file (in this example it's "text.html"), and press ctrl + shift + b to view your page in your Web Browser.
您现在可以在浏览器中安装一个扩展视图。我在chrome的windows上测试了它,它是工作的。
Vscode版本:1.10.2
下面是如何在Windows的多个浏览器中运行它
{
"version": "0.1.0",
"command": "cmd",
"args": ["/C"],
"isShellCommand": true,
"showOutput": "always",
"suppressTaskName": true,
"tasks": [
{
"taskName": "Chrome",
"args": ["start chrome -incognito \"${file}\""]
},
{
"taskName": "Firefox",
"args": ["start firefox -private-window \"${file}\""]
},
{
"taskName": "Edge",
"args": ["${file}"]
}
]
}
注意,我没有为edge在args中输入任何东西,因为edge是我的默认浏览器,只是给了它文件名。
编辑:你也不需要-incognito或-private-window…只有我,我喜欢在私人窗口看
VSCode任务-通过应用程序包标识符打开(仅限macOS)。
{
"version": "2.0.0",
"tasks": [
{
"label": "Open In: Firefox DE",
"type": "process",
"command": "open",
"args": ["-b", "org.mozilla.firefoxdeveloperedition", "${file}"],
"group": "build",
"problemMatcher": [],
"presentation": {
"panel": "shared",
"focus": false,
"clear": true,
"reveal": "never",
}
}
]
}
在Opera浏览器中打开文件(Windows 64位)。只要加上这几行:
{
"version": "0.1.0",
"command": "opera",
"windows": {
"command": "///Program Files (x86)/Opera/launcher.exe"
},
"args": ["${file}"] }
注意command:行的路径格式。不要使用“C:\path_to_exe\runme.exe”格式。
要运行此任务,请打开要查看的html文件,按F1,键入task opera并按enter