最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

dom events - JavaScript alert with confirmation - Stack Overflow

programmeradmin0浏览0评论

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 as 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);

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 as 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);
Share Improve this question edited Feb 2, 2022 at 15:10 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Dec 18, 2009 at 15:16 KobojunkieKobojunkie 6,56532 gold badges112 silver badges164 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 4

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?
        }        
    }
    });
});
发布评论

评论列表(0)

  1. 暂无评论