views:

242

answers:

1

I'm trying to return focus to the textbox after showing message. Like the following code:

<input type="text" id="text1" />
<input type="submit" id="submit1" onclick="alert('test');document.getElementById('text1').focus();return false;" />

It's not working in Safari. I've got version 4.0.5 for Windows.

A: 

This doesn't work for me either, and I suspect it's related to Safari's unwillingness to claim overall window focus after it's lost it. That's just a theory, however, as I know nothing about Safari internals, but I'm pretty sure it doesn't support window.focus() at all. Thus my thinking is that the browser window kind-of thinks that it's not the focused window, and so it ignores any attempts to focus anything.

I've sort-of confirmed this theory with this test page: http://gutfullofbeer.net/safari_focus.html

If you click the "click me" button there, and then dismiss the alert popup, and then immediately click just anywhere on the browser window (not the text box), then after a couple seconds the text box will get focus.

Pointy