FireFox 1.5的兼容性问题

     最近有朋友反映博客园首页左边的Google站内搜索在FireFox 1.5中有问题,点击“搜索”按钮没有反应,而在搜索框中通过回车键可以进行搜索。
     这个搜索功能以前在IE与FireFox都能正常使用,我在FireFox 1.0.7中测试没问题。然后我下载安装了FireFox 1.5.3,测试了一下,果然有问题。
     Google站内搜索的主要代码是这样写的:
<script language="JavaScript">
function SearchGoogle(key,evt)
        {
            
if(evt.keyCode==13 || evt.keyCode==0 )
            {
                
var keystr = encodeURIComponent(key.value);
                url 
= "http://www.google.com/search?q=";
                url 
= url+keystr;
                window.location 
=url;
            }
        }
</script>
<H2>Google站内搜索</H2>
<h4><input  type="text" name="q" onkeydown="SearchGoogle(q,event)"><input onclick="SearchGoogle(q,event)" type="button" value="搜索" name="sa"></h4>
     当时正因为考虑到FireFox的兼容性,才通过方法参数传递事件,现在反而是FireFox带来了兼容性问题。以前在FireFox中,点击按钮,evt.keyCode的返回值是0,现在在FireFox 1.5中的返回值却是undifined,问题就出在这里,这么一个很小的兼容性问题也许会给用户带来不少的麻烦,会造成在以前版本的FireFox中正常使用的功能却在FireFox 1.5中不能使用。期待FireFox在兼容性方面做得更好,尤其是与IE的兼容性,这样会方便网站的设计人员,减轻他们考虑兼容两种浏览器的负担。
     对于这个问题的解决方法,只要稍微增加一点代码,对evt进行另外的判断就行了。
<script language="JavaScript">
function SearchGoogle(key,evt)
        {
            
if(evt.keyCode==13 || evt.keyCode==0 || evt.type =='click')
            {
                
var keystr = encodeURIComponent(key.value);
                url 
= "http://www.google.com/search?q=";
                url 
= url+keystr;
                window.location 
=url;
            }
        }
</script>
<H2>Google站内搜索</H2>
<h4><input  type="text" name="q" onkeydown="SearchGoogle(q,event)"><input onclick="SearchGoogle(q,event)" type="button" value="搜索" name="sa"></h4>
posted @ 2006-05-06 19:04  dudu  阅读(1188)  评论(1编辑  收藏  举报