Reputation: 2257
I'm a beginner at JavaScript.
I've read that when an alert box pops up, the user will have to click "OK" to proceed.
However, this Alert Box Demo (jsfiddle) does not stop at OK?
<html>
<body>
<button onclick='alert(window.location="https://www.google.com");'>Google</button>
</body>
</html>
Upvotes: 1
Views: 94
Reputation: 31992
Use confirm
, which prompts for user confirmation, instead of alert
:
const button = document.querySelector('button');
button.addEventListener('click', function(){
var confirmed = confirm("Redirect?");
if(confirmed){
window.location="https://www.google.com";
}
})
<html>
<body>
<button>Google</button>
</body>
</html>
Upvotes: 2