开发者

JavaScript focus in Firefox

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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜