2013-12-19 47 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 
}