2

How to 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 thing with Visual Studio Code?

I tried to manage the task.json file as:

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

also i installed the View In Browser extenstion for VSCode, but also nothing happend.

Mark
  • 143,421
  • 24
  • 428
  • 436
Hasan
  • 60
  • 1
  • 9
  • 1
    Possible duplicate of [How to view my HTML code in browser with Visual Studio Code?](https://stackoverflow.com/questions/30039512/how-to-view-my-html-code-in-browser-with-visual-studio-code) – j08691 Oct 16 '18 at 14:54

1 Answers1

1

Change your "args" option to something like:

"args": [
    "${workspaceRoot}/index.html"
],

You may need more directories to get to your index.html, I don't know your folder structure. But if index.html is in the root of your workspace the above will work.

Of course with this method you are not actually serving your web page or watching for changes to css, js or html so you would need to refresh your browser each time to see any changes.

Mark
  • 143,421
  • 24
  • 428
  • 436
  • we should use double backslash " \\" to avoid the escape character warning in VSC: `"${C:\\Users\\Toshiba\\gamelayout\\index.html}"` – Hasan Feb 19 '18 at 05:27
  • 1
    I didn't get any warning when I tested this exact code but I am glad you have it working. – Mark Feb 19 '18 at 05:28