浏览器兼容是个大大的问题!
navigator.userAgent.toLowerCase() 来判断浏览器类型
js判断
function userBrowser(){ var browserName=navigator.userAgent.toLowerCase(); if(/msie/i.test(browserName) && !/opera/.test(browserName)){ alert("IE"); return ; }else if(/firefox/i.test(browserName)){ alert("Firefox"); return ; }else if(/chrome/i.test(browserName) && /webkit/i.test(browserName) && /mozilla/i.test(browserName)){ alert("Chrome"); return ; }else if(/opera/i.test(browserName)){ alert("Opera"); return ; }else if(/iPad/i){ alert("ipad"); return ; }else if(/webkit/i.test(browserName) &&!(/chrome/i.test(browserName) && /webkit/i.test(browserName) && /mozilla/i.test(browserName))){ alert("Safari"); return ; }else{ alert("unKnow"); } }
** 判断ipad:
(navigator.userAgent.toLowerCase().match(/iPad/i) == "ipad") ? window.pageYOffset : Math.max
(d.documentElement.scrollTop, d.body.scrollTop);
判断客户端是否为ipad,是的话采用 window.pageYOffset获取滚动轴高度; 否则采用 Math.max
(d.documentElement.scrollTop, d.body.scrollTop)