javascriptneutralinojs

NeutralinoJS Open local html file in browser


In my Neutralino app I have a navigation. When I click on a specific navigation item, I want a local html to open in the browser (or new window). The html file to open is in a subfolder of my app resources directory.

My first approach was to call the relative URL in the main.js file via Neutralino.app.open (in my config.json "url" is set to "/resources/"), without success.

window.myApp = {
openDocumentation: () => {
  Neutralino.app.open({
    "url": "/help/help.html"
  });
}
}

Next I tried to get the local app path to set an absolute path.

async function getStartupDir(){
    let response = await Neutralino.os.execCommand({
        command: 'CD'
    });
    return response.output;
}

window.myApp = {
openDocumentation: () => {
  getStartupDir().then(myValue => {
    myValue = myValue.replace(/\\/g,"/");               
    Neutralino.app.open({
      "url": "http://"+myValue+"help/help.html"
    });
  });       
}
}

That does not work either.

Is there any way to achieve this with neutralinojs?


Solution

  • I have found an answer myself. In Neutralino there is a global variable NL_CWD that contains the app path. With that path I can directly open the local html file in browser via file:/// ...

    The solution:

    window.myApp = {
      openDocumentation: () => {    
        Neutralino.app.open({
          "url": "file:///"+NL_CWD+"/resources/help/help.html"
        });
      }
    }
    

    And of course:

    window.myApp.openDocumentation();