Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing the default title of confirm() in JavaScript?

Tags:

javascript

Is it possible to modify the title of the message box the confirm() function opens in JavaScript?

I could create a modal popup box, but I would like to do this as minimalistic as possible. I would like to do something like this:

confirm("This is the content of the message box", "Modified title"); 

The default title in Internet Explorer is "Windows Internet Explorer" and in Firefox it's "[JavaScript-program]." Not very informative. Though I can understand from a browser security stand point that you shouldn't be able to do this.

like image 748
pr0nin Avatar asked Sep 04 '08 15:09

pr0nin


People also ask

What is confirm () function in JavaScript?

Definition and Usage The confirm() method displays a dialog box with a message, an OK button, and a Cancel button. The confirm() method returns true if the user clicked "OK", otherwise false .

How do I change the Confirm window button text?

Change Button Label Using jQuery and CSS We have learned to change the label of the button of the confirm box by creating the custom confirm box. Also, we can use the custom libraries to style the confirm box. Now, we can set the button label in confirm box according to the confirmation message.

How can write confirm box in JavaScript?

Confirm Box In this scenario, use the built-in function confirm() . The confirm() function displays a popup message to the user with two buttons, OK and Cancel . The confirm() function returns true if a user has clicked on the OK button or returns false if clicked on the Cancel button.

Should I use confirm JavaScript?

It is a matter of opinion but I would like to venture mine: the confirm is OK but not great. If you want a professional, clean site, use jQuery or something to generate a nice HTML popup. Second, if you can possibly avoid it, don't do confirm dialogs at all. They're annoying and often disregarded.


2 Answers

This is not possible, as you say, from a security stand point. The only way you could simulate it, is by creating a modeless dialog window.

There are many third-party javascript-plugins that you could use to fake this effect so you do not have to write all that code.

like image 89
Espo Avatar answered Sep 26 '22 05:09

Espo


YES YOU CAN do it!! It's a little tricky way ; ) (it almost works on ios)

var iframe = document.createElement("IFRAME"); iframe.setAttribute("src", 'data:text/plain,'); document.documentElement.appendChild(iframe); if(window.frames[0].window.confirm("Are you sure?")){     // what to do if answer "YES" }else{     // what to do if answer "NO" } 

Enjoy it!

like image 43
Ramon Avatar answered Sep 22 '22 05:09

Ramon