NeutralinoJS 在浏览器中打开本地 html 文件
NeutralinoJS Open local html file in browser
在我的 Neutralino 应用程序中,我有一个导航。当我点击特定的导航项时,我希望在浏览器中打开本地 html(或新的 window)。
要打开的 html 文件位于我的应用程序资源目录的子文件夹中。
我的第一个方法是通过 Neutralino.app.open 调用 main.js 文件中的亲戚 URL (在我的 config.json “url” 中设置为"/resources/"),没有成功。
window.myApp = {
openDocumentation: () => {
Neutralino.app.open({
"url": "/help/help.html"
});
}
}
接下来我尝试获取本地app路径设置绝对路径
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 实现这个?
我自己找到了答案。
在 Neutralino 中有一个包含应用程序路径的全局变量 NL_CWD
。使用该路径,我可以通过 file:/// ...
在浏览器中直接打开本地 html 文件
解决方法:
window.myApp = {
openDocumentation: () => {
Neutralino.app.open({
"url": "file:///"+NL_CWD+"/resources/help/help.html"
});
}
}
当然还有:
window.myApp.openDocumentation();
在我的 Neutralino 应用程序中,我有一个导航。当我点击特定的导航项时,我希望在浏览器中打开本地 html(或新的 window)。 要打开的 html 文件位于我的应用程序资源目录的子文件夹中。
我的第一个方法是通过 Neutralino.app.open 调用 main.js 文件中的亲戚 URL (在我的 config.json “url” 中设置为"/resources/"),没有成功。
window.myApp = {
openDocumentation: () => {
Neutralino.app.open({
"url": "/help/help.html"
});
}
}
接下来我尝试获取本地app路径设置绝对路径
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 实现这个?
我自己找到了答案。
在 Neutralino 中有一个包含应用程序路径的全局变量 NL_CWD
。使用该路径,我可以通过 file:/// ...
解决方法:
window.myApp = {
openDocumentation: () => {
Neutralino.app.open({
"url": "file:///"+NL_CWD+"/resources/help/help.html"
});
}
}
当然还有:
window.myApp.openDocumentation();