請問window.onload跟BODY onload會衝到該怎麼解決阿[以解決]

Home Home
引用 | 編輯 long691216
2005-03-28 05:47
樓主
推文 x0
小弟是學網頁的新手  煩請哪一位大大教教小弟

第一個  這是一個閃爍文字的SCRIPT
<style>
<!--
#glowtext{
filter:glow(color=0A9DF5,strength=2);
width:100%;
}
-->
</style>
<script language="JavaScript1.2">
function glowit(which){
if (document.all.glowtext[which].filters[0].strength==2)
document.all.glowtext[which].filters[0].strength=1
else
document.all.glowtext[which].filters[0].strength=2
}
function glowit2(which){
if (document.all.glowtext.filters[0].strength==2)
document.all.glowtext.filters[0].strength=1
else
document.all.glowtext.filters[0].strength=2
}
function startglowing(){
if (document.all.glowtext&&glowtext.length){
for (i=0;i<glowtext.length;i++)
eval('setInterval("glowit('+i+')",150)')
}
else if (glowtext)
setInterval("glowit2(0)",150)
}
if (document.all)
window.onload=startglowing
</script>
<span id="glowtext"><font color="F5D20A" " face="細明體" size="3">熱門商品</font></span> <style>
<!--
#glowtext{
filter:glow(color=0A9DF5,strength=2);
width:100%;
}
-->
</style>
<script language="JavaScript1.2">
function glowit(which){
if (document.all.glowtext[which].filters[0].strength==2)
document.all.glowtext[which].filters[0].strength=1
else
document.all.glowtext[which].filters[0].strength=2
}
function glowit2(which){
if (document.all.glowtext.filters[0].strength==2)
document.all.glowtext.filters[0].strength=1
else
document.all.glowtext.filters[0].strength=2
}
function startglowing(){
if (document.all.glowtext&&glowtext.length){
for (i=0;i<glowtext.length;i++)
eval('setInterval("glowit('+i+')",150)')
}
else if (glowtext)
setInterval("glowit2(0)",150)
}
if (document.all)
window.onload=startglowing
</script>
<span id="glowtext"><font color="F5D20A" " face="細明體" size="3">熱門商品</font></span>


第二個   這是會跳出視窗的SCRIPT

<SCRIPT>
<!--
var flyingwin
var popupwidth=200
var popupheight=150
var marginright
var windowcenter
var i_top=200
var i_left=-popupwidth-50
var step=40
var timer
var waitingtime=5000
var pause=20

function showWindow() {
    flyingwin = window.open("", "flyingwin", "toolbar=no,width="+popupwidth+",height="+popupheight+",top=100,left="+(-popupwidth)+"");
    flyingwin.document.open();
    flyingwin.document.write("<html><title>自動離開的窗口</title><body><p align=center>請不要關閉,我馬上就自動滾蛋:(</body></html>");
    flyingwin.document.close();
   
    if (document.all) {
        marginright = screen.width+50
    }
    if (document.layers) {
        marginright = screen.width+50
    }
    windowcenter=Math.floor(marginright/2)-Math.floor(popupwidth/2)
    movewindow()
       
}

function movewindow() {
        if (i_left<=windowcenter) {
              flyingwin.moveTo(i_left,i_top)
              i_left+=step
              timer= setTimeout("movewindow()",pause)
        }
        else {
              clearTimeout(timer)
              timer= setTimeout("movewindow2()",waitingtime)
        }
}

function movewindow2() {
        if (i_left<=marginright) {
              flyingwin.moveTo(i_left,i_top)
              i_left+=step
              timer= setTimeout("movewindow2()",pause)
        }
        else {
              clearTimeout(timer)
              flyingwin.close()
        }
}

// -->
</SCRIPT>
<BODY onload=showWindow()></BODY>


小弟真的不懂body onload 跟window.onload  會衝到的原因  希望各位能給小弟一點意見

感激不盡

表情

獻花 x0
引用 | 編輯 kc715
2005-03-28 13:20
1樓
  
請參考附件的原始檔內容....

基本上並沒有衝到喔..............

本帖包含附件
檔名: txt test.htm.txt   (2022-06-09 14:01 / 3 KB)   下載次數:14


獻花 x0
引用 | 編輯 long691216
2005-03-28 15:09
2樓
  
下面是引用kc715於2005-03-28 13:20發表的 :
請參考附件的原始檔內容....

基本上並沒有衝到喔..............

可是字不會動阿   還有視窗也不會出現   好無奈喔   

//自動離開的窗口
<SCRIPT>
<!--
var flyingwin
var popupwidth=200
var popupheight=150
var marginright
var windowcenter
var i_top=200
var i_left=-popupwidth-50
var step=40
var timer
var waitingtime=5000
var pause=20

function showWindow() {
     flyingwin = window.open("", "flyingwin", "toolbar=no,width="+popupwidth+",height="+popupheight+",top=100,left="+(-popupwidth)+"");
     flyingwin.document.open();
     flyingwin.document.write("<html><title>自動離開的窗口</title><body><p align=center>請不要關閉,我馬上就自動滾蛋:(</body></html>");
     flyingwin.document.close();
     
     if (document.all) {
           marginright = screen.width+50
     }
     if (document.layers) {
           marginright = screen.width+50
     }
     windowcenter=Math.floor(marginright/2)-Math.floor(popupwidth/2)
     movewindow()
           
}

function movewindow() {
           if (i_left<=windowcenter) {
                 flyingwin.moveTo(i_left,i_top)
                 i_left+=step
                 timer= setTimeout("movewindow()",pause)
           }
           else {
                 clearTimeout(timer)
                 timer= setTimeout("movewindow2()",waitingtime)
           }
}

function movewindow2() {
           if (i_left<=marginright) {
                 flyingwin.moveTo(i_left,i_top)
                 i_left+=step
                 timer= setTimeout("movewindow2()",pause)
           }
           else {
                 clearTimeout(timer)
                 flyingwin.close()
           }
}
</SCRIPT>
<BODY onload=showWindow()></BODY>



------------------------

//心跳樣式的文字

<style>
<!--
#glowtext{
filter:glow(color=0A9DF5,strength=2);
width:100%;
}
-->
</style>
<script language="JavaScript1.2">
function glowit(which){
if (document.all.glowtext[which].filters[0].strength==2)
document.all.glowtext[which].filters[0].strength=1
else
document.all.glowtext[which].filters[0].strength=2
}
function glowit2(which){
if (document.all.glowtext.filters[0].strength==2)
document.all.glowtext.filters[0].strength=1
else
document.all.glowtext.filters[0].strength=2
}
function startglowing(){
if (document.all.glowtext&&glowtext.length){
for (i=0;i<glowtext.length;i++)
eval('setInterval("glowit('+i+')",150)')
}
else if (glowtext)
setInterval("glowit2(0)",150)
}
if (document.all)
window.onload=startglowing
</script>
<span id="glowtext"><font color="F5D20A" " face="細明體" size="3">心跳樣式的文字</font></span>


單獨都可以執行   但是串在一起自動消失的視窗不會出來  文字也不會閃爍

麻煩大大幫小弟解惑一下

獻花 x0
引用 | 編輯 kc715
2005-03-28 15:34
3樓
  
您好,小妹認為這一段應該放在<body> </body>之間

<span id="glowtext"><font color="F5D20A" " face="細明體" size="3">熱門商品</font></span> <style>
<!--
#glowtext{
filter:glow(color=0A9DF5,strength=2);
width:100%;
}
-->
</style>

因為<BODY>內含的是網頁顯示的內容.....
基本上你的原始碼本身沒啥問題

我樓上那篇就是這樣放的

獻花 x0
引用 | 編輯 xxxzzz
2005-03-28 17:12
4樓
  
我直接改kc715大大的
試試下面的代碼..兩種效果都有
重點在於把會閃的代碼放在</body>後面
然後把window.onload=startglowing
改成startglowing();

沒有很仔細看...應該還有其他方法
複製程式
<style>
<!--
#glowtext{
filter:glow(color=0A9DF5,strength=2);
width:100%;
}
-->
</style>
<style>
<!--
#glowtext{
filter:glow(color=0A9DF5,strength=2);
width:100%;
}
-->
</style>
<SCRIPT>
<!--
var flyingwin
var popupwidth=200
var popupheight=150
var marginright
var windowcenter
var i_top=200
var i_left=-popupwidth-50
var step=40
var timer
var waitingtime=5000
var pause=20

function showWindow() {
    flyingwin = window.open("", "flyingwin", "toolbar=no,width="+popupwidth+",height="+popupheight+",top=100,left="+(-popupwidth)+"");
    flyingwin.document.open();
    flyingwin.document.write("<html><title>自動離開的窗口</title><body><p align=center>請不要關閉,我馬上就自動滾蛋:(</body></html>");
    flyingwin.document.close();
    
    if (document.all) {
        marginright = screen.width+50
    }
    if (document.layers) {
        marginright = screen.width+50
    }
    windowcenter=Math.floor(marginright/2)-Math.floor(popupwidth/2)
    movewindow()
        
}

function movewindow() {
        if (i_left<=windowcenter) {
              flyingwin.moveTo(i_left,i_top)
              i_left+=step
              timer= setTimeout("movewindow()",pause)
        }
        else {
              clearTimeout(timer)
              timer= setTimeout("movewindow2()",waitingtime)
        }
}

function movewindow2() {
        if (i_left<=marginright) {
              flyingwin.moveTo(i_left,i_top)
              i_left+=step
              timer= setTimeout("movewindow2()",pause)
        }
        else {
              clearTimeout(timer)
              flyingwin.close()
        }
}

// -->
</SCRIPT> 

<BODY onload="showWindow();">
<span id="glowtext"><font color="F5D20A" " face="細明體" size="3">熱門商品</font></span>

</BODY>
<script language="JavaScript1.2">
function glowit(which){
if (document.all.glowtext[which].filters[0].strength==2)
document.all.glowtext[which].filters[0].strength=1
else
document.all.glowtext[which].filters[0].strength=2
}
function glowit2(which){
if (document.all.glowtext.filters[0].strength==2)
document.all.glowtext.filters[0].strength=1
else
document.all.glowtext.filters[0].strength=2
}
function startglowing(){
if (document.all.glowtext&&glowtext.length){
for (i=0;i<glowtext.length;i++)
eval('setInterval("glowit('+i+')",150)')
}
else if (glowtext)
setInterval("glowit2(0)",150)
}
if (document.all)
startglowing();
</script>


獻花 x0