Rocco The Taco
Rocco The Taco

Reputation: 3777

Javascript Alert prompt prior to reload()

I have an existing icon that performs a javascript reload of the page. How do I add an alert with an ok or cancel prior to executing the reload?

<a href="#" onClick="window.location.reload()"><img src="img/reload.png" alt="Reset" name="Reset" width="32" height="32" align="middle" id="Reset" /></a>

Upvotes: 0

Views: 239

Answers (2)

Dean Marsden
Dean Marsden

Reputation: 192

Well if you do a little bit of googling, it is quite simple to find. http://www.w3schools.com/js/js_popup.asp

confirm("sometext");


if (confirm("Press a button"))
{
  x="You pressed OK!";
  window.location.reload();
}
else
{
  x="You pressed Cancel!";
} 

This should help.

Upvotes: 1

zzzzBov
zzzzBov

Reputation: 179066

The command you're looking for is confirm:

if (confirm('Are you sure')) window.location.reload()

Upvotes: 2

Related Questions