How to run a HTML file from Notepad++?

7,577

Solution 1

As of the current version of Notepad++ 6.9.1, the problem with the files in sub-folders path in a web-server has not been fixed yet. The only variable for files path is $(FULL_CURRENT_PATH).

Check: Configuring Notepad++ to run php on localhost.

Maybe this issue will be fixed in the future releases of Notepad++.

Solution 2

Instead of using Chrome directly, you could use a .bat file.

Below is one version of such a .bat file that should be executed in Notepadd++ like this :

"path\to\file.bat" "$(FULL_CURRENT_PATH)"

For Windows, where the document root is in C:\inetpub\wwwroot, the .bat file is :

@echo off
set "param=%~1"
set "url=http://localhost/%param:C:\inetpub\wwwroot\=%"
start "" chrome.exe "%url%"

The general DOS syntax used above for replacing strings in a variable is :

"%variable-name:search-string=replacement-string%"

where in our case replacement-string is empty.

This simple .bat file can easily be improved to accept the string C:\inetpub\wwwroot\ as second parameter, and more.

The batch file may cause a black DOS window to appear momentarily, to disappear immediately once Chrome is launched. If it is still too annoying, see this answer.

Solution 3

Python Solution

With Np++ plugins even miracles can be achieved. I wrote a simple Np++ Python Script that achieves exactly this functionality. This solution only requires Notepad++ and the PythonScript plugin.

  1. Install Python Script from Plugins > Plugin Manager
  2. Plugins > Python Script > New Script
  3. Name it "OpenInBrowser.py" (for example) and paste the script: http://pastebin.com/wS4jThcp
  4. In the script, remember to configure your browserExeFullPath, browserUrl and your webpage's rootDir (under which the toplevel index.html would be located).
  5. Plugins > Python Script > Configuration and add your user script to the Menu (left hand list)
  6. Restart Notepad++, Settings > Shortcut Mapper > Plugin commands and map your script to a key, for instance F9. Now pressing that key will open your active document in the browser. No external solutions required.
Share:
7,577

Related videos on Youtube

Supersharp
Author by

Supersharp

Updated on September 18, 2022

Comments

  • Supersharp
    Supersharp almost 2 years

    I'd like to run a HTML page so I configured the Execute / F5 command as following:

    chrome.exe http://localhost:8080/$(FILE_NAME)

    It works when the HTML file is located in the root of my Workspace (because my HTTP Web server is set up to do so). But it doesn't work when the file is in a subfolder.

    Is there a predefined variable (i.e. $(RELATIVE_PATH)) that can be used to get the file path relative to the Workspace directory?

    Thank you by advance for your help.

    • Burgi
      Burgi about 8 years
      Does Run -> Launch in Chrome not help you?
    • harrymc
      harrymc about 8 years
      If you are using PHP, you could use http://localhost:8080/redirect.php?file=/$(FULL_CURRENT_PATH‌​) where redirect.php takes off the excessive part. See the article Configuring Notepad++ to run php on localhost.
    • harrymc
      harrymc about 8 years
      A similar answer would be to use a .bat file to do the string manipulation and call Chrome. Simple to do if you are interested.
    • undo
      undo about 8 years
      @Supersharp Ctrl+Shift+Alt+R
  • iSR5
    iSR5 about 8 years
    @Supersharp didn't read the comments section, for the environment variables check here: docs.notepad-plus-plus.org/index.php/Defining_User_Commands
  • iSR5
    iSR5 about 8 years
    @Supersharp also this is helpful : docs.notepad-plus-plus.org/index.php/External_Programs
  • Supersharp
    Supersharp about 8 years
    I wasn't able to install the "Python Script" plugin on NPP 6.9.1.
  • pKami
    pKami about 8 years
    What exactly was the problem? I had no issue installing it on 6.9.1 with the Plugin Manager - just checked. Alternatively, you can try installing it manually from npppythonscript.sourceforge.net/download.shtml
  • Supersharp
    Supersharp about 8 years
    I failed 4 times during download. I won't follow this solution because I don't want to install yet another interpreter (already hold JVM, CLR, Node, Windows' shell...) but I upvoted because it could be a preffered solution for Pyhton users.