Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"new-win-policy" event does not fire for popup windows #1519

Closed
semmel opened this issue Jan 28, 2014 · 3 comments
Closed

"new-win-policy" event does not fire for popup windows #1519

semmel opened this issue Jan 28, 2014 · 3 comments
Assignees
Milestone

Comments

@semmel
Copy link

semmel commented Jan 28, 2014

The event does not fire for windows opened by gui.Window.open()
It just works for the main window and its child iframes.
Tested with Windows 7 32bit node-webkit v. 0.9.0rc1.
For a demo paste the code into the dev console of node-webkit:

var gui = require('nw.gui');
// for the main window it works fine:
var nwWindow = gui.Window.get();
nwWindow.window.document.body.innerHTML = '<a href="https://www.google.de" target="_blank">Go to Google</a>';
nwWindow.on('new-win-policy', console.log.bind(console, "main window"));
// clicking the link now logs to the console - Fine!

// for popups the event is not fired:
var nwPopup = gui.Window.open("http://www.example.com", {
    toolbar: false, nodejs:false, "new-instance": false});
nwPopup.window.document.body.innerHTML = '<a href="https://www.google.de" target="_blank">Go to Google</a>';
nwPopup.on('new-win-policy', console.log.bind(console, "popup window"));
// clicking the link does not fire the event :-(
@rogerwang
Copy link
Member

Thanks for reporting. I'll fix this.

The event is intent to capture new window from 3rd party content. So gui.Window.open() case was left behind.

btw, you could try 'window.open()' before it's fixed.

@rogerwang rogerwang modified the milestones: v0.9.1, v0.9.0 Feb 7, 2014
@rogerwang rogerwang self-assigned this Feb 7, 2014
@rogerwang
Copy link
Member

The fix requires deeper modifications where the ID of window is handled. I tend to push it to 0.9.1 to keep 0.9.0 more stable than rc1.

@semmel
Copy link
Author

semmel commented Feb 7, 2014

That's fine. I just wanted to report.
My link replacement code

/// Overwrite links with target=_blank to open in real browser
Array.prototype.forEach.call(outputFrame.contentDocument.querySelectorAll('a[target=_blank]'),
    function(link)
    {
        link.addEventListener('click', function(evt)
            {
                gui.Shell.openExternal(link.href);
                evt.preventDefault();
            },
            false
        );
    }
);

is still in place as a workaround.
Cheers,
Matthias

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants