2013-05-31 56 views
6

我根據朋友的要求創建了一個隨機的網站東西,詢問問題是什麼(答案(互聯網笑話)是「他有嗎?這個戰利品?「目前我已經得到它來檢查給出的密碼,並根據它的對或錯來寫入文檔。但是我希望它,如果戰利品的條件滿足,重定向(After延遲5秒)來的tumblr,迷死人的網站。如果if語句滿足,如何在延遲後重定向

這是到目前爲止我的代碼:)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<html> 
    <head> 
     <title>The ultimate question</title> 
     <style> 
    body{ 
    background-color:rgb(238, 235, 229); 
    } 
    #scriptresult{ 
    font-family:calibri; 
    font-size:26px; 
    width:30%; 
    margin-left:35%; 
    text-align:center; 
    margin-top:15%; 
    border-color:rgb(91, 122, 221); 
    border-style:solid; 
    border-width:5px; 
    padding:20px; 
    background-color:rgb(240, 219, 200);  
    } 

    </style> 
    </head> 
    <body> 
    <div id="scriptresult"> 


<script language="Javascript"> 
var passcode; 
passcode = prompt("What is the ultimate question? (Make sure to include the ? at the end)"); 
passcode = (passcode.toUpperCase()); 
document.write("Your guess was" + " " + passcode); 
if (passcode == "DO HE GOT A BOOTY?" || passcode == "DO HE GOT THE BOOTY?" || passcode == "DO HE GOT DA BOOTY?") { 
    document.write("<br>Congratulations! You got da answer! Visit the awesomness!"); 
    else if (passcode == "DOCTOR WHO?" || passcode == "WHAT IS THE MEANING OF LIFE?" || passcode == "WHAT IS THE DOCTORS NAME?" || passcode == "WHAT IS THE DOCTOR'S NAME?") { 
     document.write("<br>Not quite... But I love the guess! Think along the line of booty...<br><h6>(Hit refresh to try again)</h6>"); 
    } else { 
     document.write("<br>Nope. That's wrong.<br><h6>(Hit refresh to try again)</h6>"); 
    } 
</script> 
</div> 
</body> 
</html> 

非常感謝你提前!

回答

1

插入此代碼到你的成功條件。

setTimeout(function(){window.location.href="tumblr.com"},5000); 
+0

非常感謝你!這非常出色!我會投你一票,但我需要聲望......但是啊..謝謝你:) –

0

這會讓你在五秒鐘後執行一個功能。

setTimeout(function() { 
    // Do redirect here... 
}, 5000); 
0

在你路過的if語句:

window.setTimeout(function() { 
    location.href = "www.tumblr.com"; //is this the right link? 
}, 5000); 
+0

我只需添加http://就可以了,它的工作非常出色!謝謝:) –