在我的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"
});
});
}
}这也不起作用。
有没有办法通过neutralinojs来实现这一点呢?
发布于 2021-08-02 11:58:18
我自己找到了答案。在Neutralino中,有一个包含应用程序路径的全局变量NL_CWD。通过该路径,我可以通过file:///在浏览器中直接打开本地html文件。
解决方案:
window.myApp = {
openDocumentation: () => {
Neutralino.app.open({
"url": "file:///"+NL_CWD+"/resources/help/help.html"
});
}
}当然还有:
window.myApp.openDocumentation();https://stackoverflow.com/questions/68620523
复制相似问题