How to view an HTML file in the browser with Visual Studio Code

前端 未结 23 1606
[愿得一人]
[愿得一人] 2020-11-28 17:43

How can I view my HTML code in a browser with the new Microsoft Visual Studio Code?

With Notepad++ you have the option to Run in a browser. How can I do the same thi

相关标签:
23条回答
  • 2020-11-28 17:44

    You can now install an extension View In Browser. I tested it on windows with chrome and it is working.

    vscode version: 1.10.2

    0 讨论(0)
  • 2020-11-28 17:44

    Updated Answer in 18 April, 2020

    Click on this Left-Bottom Manage Icon. Click Extensions or Short Cut Ctrl+Shift+X

    Then Search in Extension with this key sentence Open In Default Browser. You will find this Extension. It is better to me.

    Now right click on the html file and you will see Open in Default Browser or Short Cut Ctrl+1 to see the html file in browser.

    0 讨论(0)
  • 2020-11-28 17:45

    CTRL+SHIFT+P will bring up the command palette.
    Depending on what you're running of course. Example in an ASP.net app you can type in:
    >kestrel and then open up your web browser and type in localhost:(your port here).

    If you type in > it will show you the show and run commands

    Or in your case with HTML, I think F5 after opening the command palette should open the debugger.

    Source: link

    0 讨论(0)
  • 2020-11-28 17:45

    here is how you can run it in multiple browsers for 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}"]
         }   
        ]
    }
    

    notice that I didn't type anything in args for edge because Edge is my default browser just gave it the name of the file.

    EDIT: also you don't need -incognito nor -private-window...it's just me I like to view it in a private window

    0 讨论(0)
  • 2020-11-28 17:48

    Here is a 2.0.0 version for the current document in Chrome w/ keyboard shortcut:

    tasks.json

    {
        "version": "2.0.0",
        "tasks": [
            {
                "label": "Chrome",
                "type": "process",
                "command": "chrome.exe",
                "windows": {
                    "command": "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"
                },
                "args": [
                    "${file}"
                ],
                "problemMatcher": []
            }
        ]
    }
    

    keybindings.json :

    {
        "key": "ctrl+g",
        "command": "workbench.action.tasks.runTask",
        "args": "Chrome"
    }
    

    For running on a webserver:

    https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer

    0 讨论(0)
  • 2020-11-28 17:49

    If you're just on Mac this tasks.json file:

    {
        "version": "0.1.0",
        "command": "open",
        "args": ["${file}"],
    }
    

    ...is all you need to open the current file in Safari, assuming its extension is ".html".

    Create tasks.json as described above and invoke it with +shift+b.

    If you want it to open in Chrome then:

    {
        "version": "0.1.0",
        "command": "open",
        "args": ["-a", "Chrome.app", "${file}"],
    }
    

    This will do what you want, as in opening in a new tab if the app is already open.

    0 讨论(0)
提交回复
热议问题