admin管理员组文章数量:1323208
This code works fine in <= IE7, but it doesn't work in firefox .. i am using firefox browser 12.0 .. I am not sure whats the reason .. help would be much appreciated .. thanks ..
<head>
<script type="text/javascript">
function getfocus(obj){
if(obj.value.length==0){
alert("Please enter something");
obj.focus();
}
}
</script>
</head>
<body>
<input type="text" onblur="getfocus(this)" value="Get focus">
</body>
</html>
This code works fine in <= IE7, but it doesn't work in firefox .. i am using firefox browser 12.0 .. I am not sure whats the reason .. help would be much appreciated .. thanks ..
<head>
<script type="text/javascript">
function getfocus(obj){
if(obj.value.length==0){
alert("Please enter something");
obj.focus();
}
}
</script>
</head>
<body>
<input type="text" onblur="getfocus(this)" value="Get focus">
</body>
</html>
Share
Improve this question
edited May 26, 2012 at 12:39
Sanath
4,88611 gold badges57 silver badges87 bronze badges
asked May 25, 2012 at 11:30
Sakthivel ViswanathanSakthivel Viswanathan
832 silver badges6 bronze badges
2
- what exactly happens on Firefox? What are you expecting? – Fabrizio Calderan Commented May 25, 2012 at 11:34
- What part isn't working? Where does it break/stop? Any errors in your JavaScript console? – David Thomas Commented May 25, 2012 at 11:34
3 Answers
Reset to default 5try:
....
alert("Please enter something");
setTimeout(function() {
obj.focus()
}, 10);
Some browsers, notably Firefox, have user-specific settings which control whether focus may be 'stolen' from the user. I think this may be your problem here.
However, you might want to re-consider your tactics here for ensuring the user enters some text. Having an alert pop-up every time you unfocus a blank text field would be extremely irritating to most users.
The code is working fine to me both on FF 12 and Chrome. You need to clear the input filed and then get out of the item in order to see the alert...
本文标签: htmlJavascript focus not working in firefoxStack Overflow
版权声明:本文标题:html - Javascript focus not working in firefox - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742120655a2421677.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论