【问题标题】:NeutralinoJS Open local html file in browserNeutralinoJS 在浏览器中打开本地 html 文件
【发布时间】:2021-08-02 11:06:27
【问题描述】:

在我的 Neutralino 应用程序中,我有一个导航。当我单击特定导航项时,我希望在浏览器(或新窗口)中打开一个本地 html。 要打开的 html 文件位于我的应用资源目录的子文件夹中。

我的第一种方法是通过 Neutralino.app.open 调用 main.js 文件中的相对 URL(在我的 config.json 中“url”设置为“/resources/”),但没有成功。

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

接下来我尝试获取本地应用路径来设置绝对路径。

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"
    });
  });       
}
}

这也不行。

有没有什么方法可以用中性点实现这个?

【问题讨论】:

    标签: javascript neutralinojs


    【解决方案1】:

    我自己找到了答案。 在 Neutralino 中有一个全局变量 NL_CWD 包含应用程序路径。使用该路径,我可以通过 file:/// 在浏览器中直接打开本地 html 文件 ...

    解决办法:

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

    当然还有:

    window.myApp.openDocumentation();
    

    【讨论】:

      猜你喜欢
      • 2011-11-09
      • 2016-04-20
      • 2015-04-08
      • 2021-12-09
      • 2013-08-28
      • 2014-04-27
      • 1970-01-01
      • 2012-05-11
      • 1970-01-01
      相关资源
      最近更新 更多