Closed cperryk closed 8 years ago
+1. I have exactly the same issue. Tested with latest build for OS X (ia32 and x64) - http://dl.nwjs.io/live-build/04-14-2015/e62c9f3-0aa4273-be948af-459755a-2bdc251-1764a45/
I'm loading my content in an iframe from a web site I control.
I tried to work around this issue using postMessage
in the parent html (loaded through main:
in package.json) and window.onmessage
in the target html page, loaded in the iframe.
A console.log message in the window.onmessage
block activates reliably every time postMessage
is called, but .focus();
works only when the target page has been clicked by the user, as described by the OP.
I tried to work around this issue by placing .focus()
in a setTimeout
delay. I have also triggered postMessage
from a clickable element on the parent html. in both cases the `.onmessage' block executes, but focus is not transfered to the input element.
Code
Parent html:
// get target-frame's contentWindow object
targetFrame = win.window.frames['target-frame'].contentWindow;
targetFrame.postMessage('focus', '*');
Content html loaded in iframe:
window.onmessage = function(e){
if (e.data == 'focus') {
setTimeout(function () {
$('input#search').focus();
console.log('window.onmessage: focused!');
}, 2000);
}
};
package.json
"main": "app://icrumzapp/nw-bootloader.html",
"node-main": "nw-proxy",
"bg-script": "",
"node-remote": ".icrumz.com",
"no-edit-menu": true,
"macIcns": "img/app/Logo-square.icns",
"window": {
"title": "iCrumz - Start here",
"icon": "img/app/Logo-square.png",
"focus": true,
"frame": true,
"toolbar": true,
"width": 1080,
"height": 700,
"position": "center",
"min_width": 400,
"min_height": 250,
"show": false,
"resizable": true,
"single-instance": true,
"visible-on-all-workspaces": true,
"show_in_taskbar": false,
"page-cache": false
}
OS X 10.10.2 nw.js 0.12.0 io.js 1.2.0 Chromium 41.0.2272.76
+1 Exact same issue with two Iframes, when one is toggled to hidden, then toggled to show, it will not focus until the whole window is focused out and in.
I was not going to post this issue, was afraid I making too many posts -.- and concerned it was my code. Glad someone posted it and I am not alone.
+1. How is going about this issue? I hit the same issue on nw 0.12.2 OS X version.
I'm trying to set focus automatically to a iframe from the iframe's parent after the iframe is ready. But it doesn't work, I have to click the iframe manually,
@rogerwang , is there any plan to fix this bug? Although it is not a big function issue, but it really makes the user experience bad.
This should be working with latest version now.
In 0.13 we changed to an optimized architecture so more features can be supported, see http://nwjs.io/blog/whats-new-in-0.13/ and it's good for keeping up with Chromium upstream -- we released with Node.js v6.0 and new Chromium versions within 1 day after upstream release.
The new version would fixed many issues reported here and we're scrubbing them. This issue is closed as we believe it should be fixed. Please leave a message if it isn't and we'll reopen it.
In mobile test mode on Intel XDK that uses 0.11.7-rc10-dev I cant get text input focused. While same source using nw.js v0.18.3 works fine
When opening a new window in which the "new-instance" and "focus" options are set to true, and that window includes javascript that focuses upon an element inside of it (e.g.
$('input').focus()
), the focused element will not appear or behave as if focused until the user has manually clicked the window or clicked away from the window and back.For example, let's say you want a window to open and the cursor to be immediately at a text input box so that the user can begin typing straightaway. While the window will be immediately focused, the text input will not. The user inevitably has to click the text input itself or click away from the window and back.
Seemingly related: A keydown listener added to the new window will not recognize any key presses unless the user has manually clicked an element inside the window or has clicked away and back, even though the window appears focused.
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.