2013-12-19 46 views
-3

我想知道如何通過點擊警告框中的「確定」按鈕來進入網站。 這裏是我到目前爲止的代碼:去警報箱的網頁鏈接

<html> 
<script>alert(123) 
</script> 
</html> 

回答

2
<script> 
    alert(123); 

    // go to whereever you want 
    window.location.replace('http://stackoverflow.com'); 
</script> 

alert擋住,所以直到您單擊確定繼續執行代碼的等待。

0

當用戶按下「好」,所以把下面的代碼你alert()功能後,您alert()功能後,該代碼就會被執行:

window.location.href = '...'; 

這將改變用戶的窗口的位置去... 用URI替換...。您也可以撥打window.location.replace()函數。

-1

您更好地使用一個比確認警報:

if (confirm('go to stackoverflow?')) 
{ 
    window.location.replace('http://stackoverflow.com'); 
} 
else 
{ 
    // Clicked no 
}