Basically I have a script that checks database every 10 seconds and notifys user if data has changed with a javascript alert box. But I need the database also to be changed when user has seen the alert and clicked OK. So is it possible to make a javascript function run when user clicks "OK" on javascript alert?
So for example
<html>
<head>
<script type="text/javascript">
function show_alert()
{
alert("New data!");
}
</script>
</head>
<body>
<input type="button" onclick="show_alert()" value="Show alert box" />
</body>
</html>
And when user clicks OK it should run this function
function UpdateDB()
{
jQuery.ajax({
type: "POST",
url: "update.php",
data: 'condition=ok',
cache: false,
});
}
To click on the Ok button on alert, first of all we have to switch to alert with switchTo(). alert() method. Next, to click on the Ok button, we have to use accept() method. Please note we cannot identify elements on alert by inspecting on them.
One of the nice things about the built-in JavaScript alert is that - unlike virtually anything else in JavaScript - it's synchronous. It's completely blocking, and no other code will execute until it's been dismissed.
blurt is a javascript replacement for default alert(), prompt(), and confirm() functions in javascript. The equivalents in blurt are: alert() -> blurt() prompt() -> brompt()
The alert
function halts execution of the code until it's dismissed. This means that any code you want to run after the alert has been clickd can simply be placed after the call to the alert
method.
alert("New data!");
UpdateDB();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With