在Safari中发出警报后,将焦点设置为文本框 [英] Set focus to textbox after alert in Safari

查看:97
本文介绍了在Safari中发出警报后,将焦点设置为文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在显示消息后将焦点返回到文本框。如下代码:

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;" />

它在Safari中不起作用。我有适用于Windows的4.0.5版本。

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

推荐答案

这对我也不起作用,我怀疑它是相关的Safari失去它之后不愿意声称整个窗口焦点。然而,这只是一个理论,因为我对Safari内部知识一无所知,但我很确定它根本不支持 window.focus()。因此我的想法是,浏览器窗口认为它不是焦点窗口,因此它忽略了任何关注任何事情的尝试。

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.

我在这个测试页面上证实了这一理论: http://gutfullofbeer.net/safari_focus.html

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.

这篇关于在Safari中发出警报后,将焦点设置为文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆