How to handle links that open _blank windows in node-webkit properly?

ε祈祈猫儿з 提交于 2019-12-11 02:46:15

问题


I'm trying to use new-win-policy event to handle link clicks that open new windows. https://github.com/rogerwang/node-webkit/wiki/Window#new-win-policy

win.on('new-win-policy', newWinPolicyHandler);

function newWinPolicyHandler(frame, url, policy) {
    gui.Window.open(url, {
        position: 'center',
        frame: true,
        toolbar: true,
        focus: true
    });

    policy.ignore();
}

After click on a link the handler isn't called. I got the message in console:

[17120:1029/214512:INFO:CONSOLE(138)] ""Remove zombie callback for window id 1 ev: new-win-policy"", source: window_bindings.js (138)

Have no idea what to do...


回答1:


Thanks very much for posting your question. Info on doing this seems scarce. I was able to try out some variations based upon your sample. In my case I'm using an iFrame in NWJS, and was able to prevent popups, forcing the URL into the iFrame:

win.on('new-win-policy', newWinPolicyHandler);

function newWinPolicyHandler(frame, url, policy) {
    policy.ignore(); //ignore policy first to prevent popup
    $("#Your-iFrameID").attr("src",url); //load popup url into iFrame
}


来源:https://stackoverflow.com/questions/26650754/how-to-handle-links-that-open-blank-windows-in-node-webkit-properly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!