Article Introduction: troubleshoot JavaScript not compatible with other browser problems except IE. |
Today, the boss asked me to deal with a Web site compatibility issues, the general compatibility problem is compatible with other browsers, IE is not compatible, and this is a little special, only compatible with IE, not compatible with other browsers. After preliminary observation, I found it was a javacript problem. It's not about Div and CSS.
This is the original code:
<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″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>
This is actually a very ordinary carousel. The problem with incompatibility is that the code is not well written, so I'll give my solution:
<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>
Write code to improve, not only will be more compatible, will be better to see, we write procedures, do not covet a quick, we have to write a good program, must not appear as the problem.