window.focus() not working for Chrome and Firefox

I'm trying to get the window.focus() function to work with no luck.

Take a look at this fiddle

var myWindow = window.open('','zzz','width=600,height=700');
    myWindow.document.write('test');
    myWindow.focus();​

If you click run after the jsfiddle page loads then the new window should get back focus. What am I doing wrong?

Answers


It "works" for me in FF 15. Users can disable the ability of scripts to open and focus windows, check your settings. Oh, and the pop–up should get focus by default, so you shouldn't have to call myWindow.focus().

Some minor points that probably having nothing to do with the issue but you may want to fix:

  1. A valid document should be written to the new window, a title element and one block element are required, e.g. document.write('<title></title><div></div>, a DOCTYPE is highly recommended too
  2. The input stream should be closed after you've finished writing, use document.close()

Need Your Help

Underscore.js perform operation on an object, not an array

underscore.js javascript

Hey I'm new to underscore.js and I'm trying to figure out how to perform an operation on a map. I read through the API and I'm afraid I'm missing something.

Could not inspect the application package when using device

ios iphone xcode

I’m getting this error whenever I try to run my app on a device:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.