如何使用新的Microsoft Visual Studio code在浏览器中查看我的HTML代码?

使用notepad++,您可以选择在浏览器中运行。我如何用Visual Studio Code做同样的事情?


当前回答

在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

其他回答

CTRL+SHIFT+P将调出命令面板。 当然,这取决于你在运行什么。例如,在ASP.net应用程序中,你可以输入: >kestrel,然后打开web浏览器,输入localhost:(你的端口在这里)。

如果你输入>,它会显示show和run命令

或者在您使用HTML的情况下,我认为打开命令面板后的F5应该打开调试器。

来源:链接

打开自定义Chrome浏览器与URL从提示

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "Open Chrome",
      "type": "process",
      "windows": {
        "command": "${config:chrome.executable}"
      },
      "args": ["--user-data-dir=${config:chrome.profileDir}", "${input:url}"],
      "problemMatcher": []
    }
  ],
  "inputs": [
    {
      "id": "url",
      "description": "Which URL?",
      "default": "http://localhost:8080",
      "type": "promptString"
    }
  ]
}

打开自定义Chrome与活动文件

{
  "label": "Open active file in Chrome",
  "type": "process",
  "command": "chrome.exe",
  "windows": {
    "command": "${config:chrome.executable}"
  },
  "args": ["--user-data-dir=${config:chrome.profileDir}", "${file}"],
  "problemMatcher": []
},

笔记

如有必要,可将windows属性替换为其他操作系统 替换${配置:chrome。可执行}与您的自定义chrome位置,例如。"C:/Program Files (x86)/谷歌/Chrome/Application/ Chrome .exe" 替换${配置:chrome。profileDir}与您的自定义chrome配置文件目录,例如。 “C:/My/Data/chrome/profile”或省略 如果你愿意,你可以像上面那样保留变量。为此,在设置中添加以下条目。Json -用户或工作区-,根据需要调整路径:

"chrome.executable": "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe",
"chrome.profileDir": "C:/My/Data/chrome/profile"

你可以重复使用这些变量,例如在启动。"runtimeExecutable": "${config:chrome.executable}"

最近在www.lynda.com的一个visual studio代码教程中发现了这个功能

按Ctrl + K + M,它将打开“选择语言模式”(或点击右下角的HTML前面的笑脸),输入markdown并按enter

现在按Ctrl + K后面跟着V,它将打开你的html在附近的标签。

Tadaaa ! !

现在emmet命令在我的html文件中不能在这种模式下工作,所以我回到了原始状态(注- html标签tellisense工作完美)

—按“Ctrl + K + M”,选择“auto-detect”。埃米特的命令开始生效。如果你只喜欢html查看器,那么没有必要让你回到原来的状态。

不知道为什么vscode没有html查看器选项默认情况下,当它能够显示html文件在markdown模式。

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.

VS Code有一个实时服务器扩展,支持一键启动状态栏。

一些特点:

一键从状态栏启动 生活重新加载 支持Chrome调试附件