86

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
pr0nin
  • 933
  • 1
  • 7
  • 8

8 Answers8

92

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.

Espo
  • 41,399
  • 21
  • 132
  • 159
11

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!

Ramon
  • 193
  • 1
  • 7
  • 1
    Initially this created an error. Then, after placing the `if` block in a timeout, it produced the same result in Firefox. Doesn't work in Chrome. http://jsfiddle.net/pzd9pmeu/ – Oliver Moran Aug 23 '14 at 13:28
  • 2
    this changes the title to "An embedded page on this webpage says:" – ZioCain Feb 09 '18 at 11:37
  • 5
    Aw man, that's a nasty hack. I'm not saying there's anything wrong with that. But that has to go right up there with some of the nastiest hacks I've seen so far. You know- kudos for the can do spirit! – cmc Aug 24 '18 at 20:24
5

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.

Brian R. Bondy
  • 339,232
  • 124
  • 596
  • 636
3

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.

Matt Clark
  • 31
  • 1
0

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.

0

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

samjudson
  • 56,243
  • 7
  • 59
  • 69
0

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

Ben Scheirman
  • 40,531
  • 21
  • 102
  • 137
0

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.

Slartibartfast
  • 8,735
  • 6
  • 41
  • 45