DelphiFAQ Home Search:

Have a Javascript popup display Yes/ No instead of Confirm/ Cancel


comments72 comments. Current rating: 4 stars (24 votes). Leave comments and/ or rate it.


I need to ask my web site's user a Yes/ No question. Currently I use JavaScript's confirm() function.
The return value is true (OK) or false (CANCEL).
The word CANCEL is misleading. I want to have the buttons say Yes/ No instead.
How can I do it?


Many people will tell you it is not possible, and that is true for standard Javascript.

However, I found the following which works at least in 32 bit Windows with IE (which often accounts for 95% of your site's users).

This solution uses vbscript's confirm() function.

No, it does not work in FireFox. FireFox will display Confirm/ Cancel.

<script language=javascript>

/*@cc_on @*/
/*@if (@_win32 && @_jscript_version>=5)

function window.confirm(str)
    execScript('n = msgbox("'+str+'","4132")', "vbscript");
    return(n == 6);

@end @*/
var r = confirm("Can you do it?");

Content-type: text/html


You are on page 2 of 5, other pages: 1 [2] 3 4 5
2008-08-02, 04:42:24
anonymous from India  
Thanks, fentastic code for windows but not working on linux.. Any suggestion ?

2008-09-11, 02:28:04
anonymous from Philippines  
highlight it on the source code and cut the code enclose by /* and */
2008-09-11, 02:28:18
anonymous from Philippines  
highlight it on the source code and cut the code enclose by /* and */
2008-09-27, 12:18:03
Excellent Post.

Very helpful.


Ujjwal B Soni


2008-11-12, 05:48:27
anonymous from India  
Thank U .It works well
but how can I get a new line
When I use '\n' in my message(str)
It show an error 'Unterminated string constant'
2008-11-18, 05:14:34
anonymous from Sweden  
Can some one let me know how to remove the 'VBScript' displayed as title ?

execScript('n = msgbox(''+str+'','4132', 'Please Confirm')', 'vbscript'); doesnot remove VBScript. It add's VBScript: Please Confirm
2008-11-26, 19:02:07
anonymous from Australia  
I think you will find that alot more then just 5% percent of users use a non IE browser. Its anywhere between 20% and 40% now depending on where you look.


You are on page 2 of 5, other pages: 1 [2] 3 4 5



NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: