Can I change the title bar caption of an alert() box?

Hello,

The title says it!

Thanks in advance…

You can’t.

Similar to a javascipt alert box, vbscript has msgbox. It allows for more customization. from http://www.aspnetcenter.com/cliktoprogram/vbscript/alert.asp
. Following are list of button arguments available in vbscript.

Constant Value Description
vbOKOnly 0 Display OK button only.
vbOKCancel 1 Display OK and Cancel buttons.
vbAbortRetryIgnore 2 Display Abort, Retry, and Ignore buttons.
vbYesNoCancel 3 Display Yes, No, and Cancel buttons.
vbYesNo 4 Display Yes and No buttons.
vbRetryCancel 5 Display Retry and Cancel buttons.
vbCritical 16 Display Critical Message icon.
vbQuestion 32 Display Warning Query icon.
vbExclamation 48 Display Warning Message icon.
vbInformation 64 Display Information Message icon.
vbDefaultButton1 0 First button is default.
vbDefaultButton2 256 Second button is default.
vbDefaultButton3 512 Third button is default.
vbDefaultButton4 768 Fourth button is default.

This is something I’ve had in the back of my mind to try. So I guess now is a good time.

I’ve only tested it in IE6 and FF1.0.6 XP (I don’t have Opera on this computer). For reasons unknown to me, FF doesn’t seem to mind the 2nd argument in alert()

This can easily be modified, see above post by Mittineague or msdn. This is IE only.

<html>
<head>
<title>my page title</title>

<script type="text/javascript">

onload=function(){
alert('1st message using the\
page title as default');
alert('2nd message with\
a different title','different title')
}

function set_ie_alert(){
window.alert=function(msg_str,title_txt){
vb_alert(msg_str,title_txt)
}
}

</script>

<script language="vbscript" type="text/vbs">

set_ie_alert()

Function vb_alert(msg_str,title_txt)
MsgBox msg_str,vbOKOnly + vbExclamation + vbApplicationModal,vb_title(title_txt)
End Function

Function vb_title(title_txt)
If title_txt = Empty Then
vb_title = document.title
Else
vb_title = title_txt
End If
End Function

</script>
</head>
<body>
</body>
</html>

as a side note, this would be an easy IE sniffer


<script type="text/javascript">
var ie=0;
</script>

<script language="vbscript" type="text/vbs">
ie = 1
</script>

A cross-browser DHTML alternative: http://slayeroffice.com/code/custom_alert/

Well that 2nd argument in alert() was bugging me. Here’s the same idea with 1 argument. Note that the warning icon is changed to the information icon.

<html>
<head>
<title>my page title</title>

<script type="text/javascript">

var dialogue_title=document.title;

onload=function(){
alert('1st message using the\
page title as default');
dialogue_title='Custom Title';
alert('2nd message with\
a custom title')

}

function set_ie_alert(){
window.alert=function(msg_str){
vb_alert(msg_str)
}
}

</script>

<script language="vbscript" type="text/vbs">

set_ie_alert()

Function vb_alert(msg_str)
MsgBox msg_str,vbOKOnly + vbInformation + vbApplicationModal,dialogue_title
End Function

</script>
</head>
<body>
</body>
</html>