如果设置了window.location.href,则node-webkit不会最小化到托盘
发布时间:2020-12-14 05:34:02 所属栏目:Windows 来源:网络整理
导读:Windows 7 x64,nwjs 0.19.4 最小化托盘工作正常而不设置window.location.href,但设置nwjs时不会最小化到托盘. 每个请求修订的代码: 的index.html htmlbodydiv/divscript // Load library var gui = require('nw.gui'); // Reference to window and tray var
Windows 7 x64,nwjs 0.19.4
最小化托盘工作正常而不设置window.location.href,但设置nwjs时不会最小化到托盘. 每个请求修订的代码: 的index.html <html> <body> <div></div> <script> // Load library var gui = require('nw.gui'); // Reference to window and tray var win = gui.Window.get(); var tray; onload = function () { window.location.href = "http://iheartradio.com" }; // Get the minimize event win.on('minimize',function () { // Hide window win.hide(); var tray = new nw.Tray({ title: 'Web Music Player',icon: 'img/music.png' }); // Show window and remove tray when clicked tray.on('click',function () { win.show(); this.remove(); tray = null; }); }); </script> </body> </html> 的package.json { "name": "webmusicplayer","version": "0.1.0","main": "index.html","single-instance": true,"window": { "title": "webmusicplayer","min_width": 1200,"min_height": 600 },"webkit": { "plugin": true },"chromium-args": "--load-plugin=ffmpegsumo.dll --child-clean-exit --disable-direct-composition --allow-running-insecure-content --no-proxy-server --enable-video-player-chromecast-support" } 解决方法
您的代码的主要问题是您在使用window.location重新加载之后在窗口对象上注册最大化事件,因此您的javascript代码将被删除并进行垃圾回收.
你需要在每次重新加载后注入你的js代码 以下是根据您的要求的完整工作代码 home.html的 <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>Tray Demo</title> <script type="text/javascript"> console.log('redirecting the page'); window.location.href = 'http://www.microsoft.com'; </script> </head> <body> <p>redirecting the page...</p> </body> </html> 的package.json { "main": "home.html","name": "tray-demo","description": "tray demo for windows","version": "1.0","inject_js_start": "NWInit.js","window": { "title": "Tray Demo","resizable": true,"show_in_taskbar": true },"node-remote": "*://*" } NWInit.js if(typeof nw != 'undefined') { NWInit = { initApp: function() { console.log('init app called'); var win = nw.Window.get(); win.showDevTools(); win.on('minimize',function() { console.log('minimize called'); if(typeof nw.Tray == 'undefined') { return; } win.hide(); var tray = new nw.Tray({ title: 'Web Music Player',icon: 'img/music.png' }); tray.on('click',function() { console.log('tray clicked'); win.show(); tray.remove(); tray = null; }); }); } }; NWInit.initApp(); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
热点阅读