JavaScript alert with confirmation
I have a JavaScript alert popup on my page. Problem I am having with it is that instead of waiting for the user to actually click the OK button, it simply does a redirect, something it ought to do AFTER the OK button has been clicked. Can anyone please help me tweak my code so a开发者_如何学编程s to get this working as it ought to please?
function f()
{
ar ape =radalert('<div align=""center"" style=""font-weight: bold;""> OPEN BOX HERE</div>', 123, 200);
if(ape)window.location.href = "/Default.aspx";
Sys.Application.remove_load(f);
}
Sys.Application.add_load(f);
You can use the add_close
method to attach a callback function to know when the alert is closed:
var win = radalert('foo');
win.add_close(function () {
alert('bar'); // This will be executed when the radalert is closed.
});
More info:
- Telerik RadWindow Client-Side API
You're not using a JavaScript alert
(in the sense of the built-in function), it looks like you're using something called radalert
(from Telerik). That means it can't behave like a JavaScript alert
, which brings script processing to a screeching halt while it's on-screen.
I know nothing about Telerik, but most of these alert replacements offer a callback you can pass that gets triggered when the alert is cleared. That's where you want your window.location.href = ...
code.
Usually this looks something like this:
function blah() {
niftyAlertThingy("Here's my message", {
onOK: function() {
window.location.href = "/Default.aspx";
// etc.
}
});
}
That blah
function returns immediately, with the alert still on the page; then the alert code calls your callback when the user clicks OK.
I'm sure the Telerik radalert
has something similar...
I would think your code would need more explanation and possibly your code behind too (just the relevant code on how you handle "OK" Click). My experience with telerik is not good. I would suggest you to try jQuery UI. It gives you better control on how you can handle events and where.
Example( From here)
$(function(){
$("#dialog").dialog({
autoOpen: false,
modal:true,
buttons : {
"Yes" : function() {
$(this).dialog("close");
eval($("#<%= hdnBtnPostback.ClientID %>").val());
},
"No" : function() {
$(this).dialog("close");
},
"Maybe": function() {
$(this).dialog("close");
//what should we do when "Maybe" is clicked?
}
}
});
});
精彩评论