简体   繁体   中英

script only works in IE

I have the following JavaScript for show running line:

<script type="text/javascript" language="javascript">


//Change script's width (in pixels)
var marqueewidth=800
//Change script's height (in pixels, pertains only to NS)
var marqueeheight=20
//Change script's scroll speed (larger is faster)
var speed=3
//Change script's contents
var marqueecontents='You text here'

if (document.all)
document.write('<marquee scrollAmount='+speed+' style="width:'+marqueewidth+'">'+marqueecontents+'</marquee>')

function regenerate(){
window.location.reload()
}
function regenerate2(){
if (document.layers){
setTimeout("window.onresize=regenerate",450)
intializemarquee()
}
}

function intializemarquee(){
document.cmarquee01.document.cmarquee02.document.write('<nobr>'+marqueecontents+'</nobr>')
document.cmarquee01.document.cmarquee02.document.close()
thelength=document.cmarquee01.document.cmarquee02.document.width
scrollit()
}

function scrollit(){
if (document.cmarquee01.document.cmarquee02.left>=thelength*(-1)){
document.cmarquee01.document.cmarquee02.left-=speed
setTimeout("scrollit()",100)
}
else{
document.cmarquee01.document.cmarquee02.left=marqueewidth
scrollit()
}
}

window.onload=regenerate2
</script>

What should I change in script to make it work in FF and Chrome? Thanks

Your code contains the line if (document.all) so the Marquee only gets written to the document in IE.

I've deleted this line and it appears to work in Firefox. I don't have Chrome on this machine to test.

  1. missing semicolons
  2. document.write()
  3. document.all
  4. <marquee>
  5. globals
  6. string as setTimeout function
  7. no indentation

Nostalgia... it's like it's 1998.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM