解决javascript不兼容除IE外其他浏览器问题

王朝学院·作者佚名  2016-04-29
窄屏简体版  字體: 小  |  中  |  大  |  超大  

今天,老大要我处理一个网站的兼容问题,一般兼容性问题是兼容其他浏览器,就IE不兼容,而这个有点特殊,只兼容IE,不兼容其他浏览器。初步观察以后,我发现是javacript的问题。而不关div和CSS什么事情。

这是原来的代码:

<SCRIPT language=Javascript>

marqueesHeight=550;

stopscroll=false;

with(Flash){

style.width=235;

style.height=marqueesHeight;

style.overflowX=”visible”;

style.overflowY=”hidden”;

noWrap=true;

onmouSEOver=new Function(“stopscroll=true”);

onmouseout=new Function(“stopscroll=false”);

}

document.write(‘<div id=”templayer1&PRime; style=”position:absolute;z-index:1;visibility:hidden;top:6px;”></div>’);

preTop=0; currentTop=0;

function init1(){

templayer1.innerHTML=”";

while(templayer1.offsetHeight<marqueesHeight){

templayer1.innerHTML+=flash.innerHTML;

}

flash.innerHTML=templayer1.innerHTML+templayer1.innerHTML;

setInterval(“scrollUp1()”,20);//?

}

document.body.onload=init1;

function scrollUp1(){

if(stopscroll==true) return;

preTop=flash.scrollTop;

flash.scrollTop+=1;

if(preTop==flash.scrollTop){

flash.scrollTop=templayer1.offsetHeight-marqueesHeight;

flash.scrollTop+=1;

}

}

</SCRIPT>

这其实就是很普通的轮播。而造成不兼容的问题就是因为代码写的不完善,下面我给出我的解决方案:

<SCRIPT language=JavaScript>

marqueesHeight=550;

stopscroll=false;

var marquees=document.getElementById(“flash”);

var templayer=document.getElementById(“templayer1″);

with(flash){

flash.style.width=235+”px”;

flash.style.height=marqueesHeight+”px”;

flash.style.overflowX=”visible”;

flash.style.overflowY=”hidden”;

flash.noWrap=true;

flash.onmouseover=new Function(“stopscroll=true”);

flash.onmouseout=new Function(“stopscroll=false”);

}

document.write(‘<div id=”templayer1″ style=”position:absolute;z-index:1;visibility:hidden;top:6px;”></div>’);

var preTop=0; currentTop=0;

function init1(){

templayer1.innerHTML=”";

while(templayer1.offsetHeight<marqueesHeight){

templayer1.innerHTML+=flash.innerHTML;

}

flash.innerHTML=templayer1.innerHTML+templayer1.innerHTML;

setInterval(“scrollUp1()”,10);//?

}

window.onload=init1;

function scrollUp1(){

if(stopscroll==true) return;

preTop=flash.scrollTop;

flash.scrollTop+=1;

if(preTop==flash.scrollTop){

flash.scrollTop=templayer1.offsetHeight-marqueesHeight;

flash.scrollTop+=1;

}

}

</SCRIPT>

将代码写完善,不仅仅会更兼容,也会更好看,我们写程序,千万不要贪图一时的快速,我们要写出好程序,千万不能出现如上的问题。

除非注明,胡小易博客文章均为原创,转载请以链接形式标明本文地址

本文地址:http://huxiaoyi.com/website/20120706.html

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝網路 版權所有 導航