Found a workaround for a window focus problem with Google’s Chrome browser.
Summary:
var w = window.open(url, ‘windowname’, ‘…’);
w.focus();
Problem is that the “focus” call doesn’t work … the 2nd time you call this function.
The workaround requires you to retain a pointer to the window as a global, and just close it before opening it again, like so:
if (navigator.userAgent.indexOf('Chrome/') > 0) { if (window.detwin) { window.detwin.close(); window.detwin = null; } } window.detwin = window.open(URL, 'windowname', '...'); window.detwin.focus();
Hard-coded it for Chrome as it works in all other browsers, except for Chrome.
The bug on the Google site references a potential issue with Webkit, but the latest version of Safari doesn’t have the issue at all.
Comment if this helped you!
11 replies on “Chrome problems with window focus (workaround)”
Google chrome is light and fast, but it seems like it’s having some problem with javascripts.
u can do some thing like this:
in parent:
var w = window.open(href,’name’);
if(w.focus)
w.focus();
in child window:
if(window.parent && (navigator.userAgent.indexOf(‘Chrome/’) > 0)
window.parent.blur();
This method faster, and u can open focus window many times without storing var w = …
sorry for my engliache ))))
Instead of closing the popup, then open a new one,
I’ve found out the following sequence was also fixing the Chrome (WebKit) bug.
if(typeof(win)!=’undefined’ && !win.closed) {
win.blur();
}
else {
win = window.open(mypage_location, mypage_name, mypage_option);
}
win.focus();
In other words, if you use blur() on the window first then focus() function works.
Note: We’re currently using Chrome 3.0.195.21 / working on XP.
I haven’t tested yet on Safari and/or other platforms, any feedbacks on other platforms will be well-appreciated.
Thanks.
Works in:
IE 6+
Firefox 3
Chrome 3
Does not work in:
Safari 3.1
Opera 9.63
Works for me in
IE8
FireFox 3.5.8
Windows Safari 4.0.4
Chrome 4.1
Does not work in Opera 9.64
Thanks a lot, work fine for me!
var nextObject = document.getElementById(“select_combo_box”);
nextObject.focus();
———————————————–
that example is not working in Chrome and safari.
Please give correct example for it that can run on every browser using Javascript or jQuery or MooTools
This method (to call blur() then focus() ) does not work for me on Chrome 5.0.375.126 on Mac OS X.
Any workarounds found for Chrome on Mac?
@Nick: The original method (closing, then opening) in the post above does work on Chrome 5.0.375.126 on Mac OS X. I haven’t tried the alternate methods proposed…
Call nameOfVarWindow.blur(); before nameOfVarWindow.focus();
Took the solution from here: http://stackoverflow.com/questions/2758608/window-focus-not-working-in-google-chrome
As of Chrome 13.0.782.112, widow.parent.blur() minimizes the window… Aaaaaargh… :-/