JavaScript focus in Firefox - Stack Overflow

I want to focus on a special textbox when the page is loaded. I do this with JavaScript function, focus

I want to focus on a special textbox when the page is loaded. I do this with JavaScript function, focus(), and it works fine. But when I open the page in a new tab in Firefox, it doesn't focus on the textbox.

Any idea?

I want to focus on a special textbox when the page is loaded. I do this with JavaScript function, focus(), and it works fine. But when I open the page in a new tab in Firefox, it doesn't focus on the textbox.

Any idea?

Share Improve this question edited Jan 8, 2020 at 3:32 Peter Mortensen 31.6k22 gold badges110 silver badges133 bronze badges asked Nov 8, 2009 at 7:59 AliBZAliBZ 4,09912 gold badges47 silver badges68 bronze badges 1
  • I'm developing with zend platform and it's a huge project. after all it is not an special code. It is something like code below which priyanka wrote. – AliBZ Commented Nov 8, 2009 at 9:35
Add a ment  | 

3 Answers 3

Reset to default 4

Yep. It doesn't work in Firefox. I don't know why. But it works, if we do the following in Firefox. Go to menu ToolsOptions. Click on Tabs.

Check the option "When I open a link in a new tab, switch to it immediately".

This will take you to the opened tab directly and onfocus works. This is not the solution. This will work only on your Firefox of course. You can't guarantee users have that option checked. :(

Firefox opens in a new tab opens in a background tab. If the page itself doesn't have focus, then it can't pass its focus to any element within the page.

In order to achieve the desired effect, you will need to set the focus on the control when the document first gains focus.

I agree with Mr.Paul. Here is a simple example:

<HTML>
    <HEAD>
        <TITLE> New Document </TITLE>
        <script language="javascript">
            <!--
                function SetFocus()
                {
                    document.getElementById('t1').focus();
                }

            //-->
        </script>
    </HEAD>

    <BODY onLoad="SetFocus()">
        <input type="text" id="t1">
        <input type="text" id="t2">
    </BODY>
</HTML>

Setting the focus on the first textbox. Whenever the new tab opens, set the proper URL and the first textbox will gain the focus.

Moreover, when the new tab is clicked, the URL is not set to the actual URL of the file. After setting the URL you will definitely find the textbox1 is having the focus.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744902666a4600068.html

相关推荐

  • JavaScript focus in Firefox - Stack Overflow

    I want to focus on a special textbox when the page is loaded. I do this with JavaScript function, focus

    1天前
    60

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信