1

I was trying to do the magic and turn all of my platform javascript alerts to jquery dialog, I followed the following scripts

<div id="overrideAlert"></div>

<script>
window.alert = function(message) {
    $('#overrideAlert').text(message).dialog({
        modal:true,
        title:'Message',
        buttons: {
            'OK':function(){
                $(this).dialog('close');
            }
        }
    });
};
</script>

But no luck.

Is there a clean solution for this? Thanks,

13
  • Do you get any messaging in the console? You have loaded jQuery and jQuery UI into the page properly, yes? Commented May 1, 2013 at 2:56
  • what is the problem your are facing Commented May 1, 2013 at 2:56
  • 2
    looks fine to me plnkr.co/edit/mzSKFsjvkSod1oqErdFF?p=preview Commented May 1, 2013 at 2:58
  • 1
    one problem could be the synchronized nature of the alert and async nature of dialog Commented May 1, 2013 at 3:00
  • Not sure about dialog, but does it auto-open or do you need to manually .open()? Commented May 1, 2013 at 3:01

4 Answers 4

8

I would prefer a dynamic div instead

$('<div />').text(message).dialog({
    modal:true,
    title:'Message',
    buttons: {
        'OK':function(){
            $(this).dialog('close');
        }
    },
    close:function(){ $(this).dialog('destroy').remove(); }
});

DEMO.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks man, say I have a link and when click, an alert pops up, does this help that scenario as well?
3

It just works.

Check at the jsfiddle demo.

Note: you can't call alert('foo'); directly inside the <head>'s <script> tags, because the div element is not ready on the dom.

1 Comment

Thanks, does your solution cover the alerts which pop up on click? say u click a link and a confirmation pop up shows up. I want to get the jquery dialog when click on these sorts of link
0

Your code looks fine, but make sure that you add jquery and jquery-ui libraries to your page.

Demo: Plunker

Comments

-1

If we are submitting page before alert is going automatically. some saved successfully messages there but not asking for "ok". I have done overriding of alert.any suggestion. window.alert = function(message, fallback){

$(document.createElement('div')).attr({title: 'Alert', 'class': 'alert'}).html(message).dialog({
  buttons: {OK: function(){$(this).dialog('close'); callback()}},
  autoOpen: true,
  close:function(){$(this).remove();},
  draggable: true,
  modal: false,
  resizable: false,
  height:'auto',
  width: 'auto'
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.