Changing the default title of confirm() in JavaScript?

Javascript

Javascript Problem Overview


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.

Javascript Solutions


Solution 1 - Javascript

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.

Solution 2 - Javascript

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!

Solution 3 - Javascript

Not possible. You can however use a third party javascript library that emulates a popup window, and it will probably look better as well and be less intrusive.

Solution 4 - Javascript

You can always use a hidden div and use javascript to "popup" the div and have buttons that are like yes and or no. Pretty easy stuff to do.

Solution 5 - Javascript

You can't unfortunately. The only way is to simulate this with a window.open call.

Solution 6 - Javascript

Don't use the confirm() dialog then... easy to use a custom dialog from prototype/scriptaculous, YUI, jQuery ... there's plenty out there.

Solution 7 - Javascript

I know this is not possible for alert(), so I guess it is not possible for confirm either. Reason is security: it is not allowed for you to change it so you wouldn't present yourself as some system process or something.

Solution 8 - Javascript

Yes, this is impossible to modify the title of it. If you still want to have your own title, you can try to use other pop-up windows instead.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionpr0ninView Question on Stackoverflow
Solution 1 - JavascriptEspoView Answer on Stackoverflow
Solution 2 - JavascriptRamonView Answer on Stackoverflow
Solution 3 - JavascriptBrian R. BondyView Answer on Stackoverflow
Solution 4 - JavascriptMatt ClarkView Answer on Stackoverflow
Solution 5 - JavascriptsamjudsonView Answer on Stackoverflow
Solution 6 - JavascriptBen ScheirmanView Answer on Stackoverflow
Solution 7 - JavascriptSlartibartfastView Answer on Stackoverflow
Solution 8 - JavascripthappylifeView Answer on Stackoverflow