penny
penny

Reputation: 11

Changing JavaScript alert buttons

How do you change the words on the buttons in a javascript alert? I am new so the simplest way possible would be greatly appreciated.

Upvotes: 1

Views: 16213

Answers (4)

ShankarSangoli
ShankarSangoli

Reputation: 69915

Try something like this

    function CustomAlert(msg){
var customAlert = $("#customAlert");
      if(!customAlert.length){
        customAlert = $(document.body).append('<div id="customAlert"><div class="message">Msg></div><div><input class="button"     type="button" value="Ok" /></div></div>').hide();
}
customAlert.find("message").html(msg);

//Code to center the customAlert into view port along with faded background will go here

customAlert.find("input.button").unbind("click").click(function(){ 
 //Hide the customAlert goes here
 customAlert.hide();
});

    }

Upvotes: 0

ShankarSangoli
ShankarSangoli

Reputation: 69915

You can overriede window.alert and have your own implemenation of it.

window.alert = function(msg, options){
     //Create the alert dialog box here using the default options and show the message.
}

You dont have to change your code in the application to use it.

Upvotes: 0

beardhatcode
beardhatcode

Reputation: 4773

not possible, the browser sets that

what you could do is make a fake alert from elements,

Upvotes: 3

SLaks
SLaks

Reputation: 888203

You can't.

Instead, you can create a fake dialog in the DOM, using jQuery UI Dialog.

Upvotes: 6

Related Questions