Reputation: 4099
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?
Upvotes: 1
Views: 3119
Reputation: 26498
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.
Upvotes: 1
Reputation: 6956
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.
Upvotes: 3
Reputation: 10255
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 Tools → Options. 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. :(
Upvotes: 4