Compatibility of Web pages: Solution JS compatible IE not compatible with other browsers

Source: Internet
Author: User
Tags return setinterval visibility

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.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.