Reputation: 4137
I'm generating a JavaScript alert with following code in C# .NET page:
Response.Write("<script language=JavaScript> alert('Hi select a valid date'); </script>");
It displays an alert box with the heading title as "Message from webpage".
Is it possible to modify the title?
Upvotes: 200
Views: 549282
Reputation: 2408
I had a similar issue when I wanted to change the box title and button title of the default confirm box. I have gone for the Jquery Ui dialog plugin http://jqueryui.com/dialog/#modal-confirmation
When I had the following:
function testConfirm() {
if (confirm("Are you sure you want to delete?")) {
//some stuff
}
}
I have changed it to:
function testConfirm() {
var $dialog = $('<div></div>')
.html("Are you sure you want to delete?")
.dialog({
resizable: false,
title: "Confirm Deletion",
modal: true,
buttons: {
Cancel: function() {
$(this).dialog("close");
},
"Delete": function() {
//some stuff
$(this).dialog("close");
}
}
});
$dialog.dialog('open');
}
Can be seen working here https://jsfiddle.net/5aua4wss/2/
Hope that helps.
Upvotes: 1
Reputation: 1215
I Found this Sweetalert for customize header box javascript.
For example
swal({
title: "Are you sure?",
text: "You will not be able to recover this imaginary file!",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes, delete it!",
closeOnConfirm: false
},
function(){
swal("Deleted!", "Your imaginary file has been deleted.", "success");
});
Upvotes: 21
Reputation: 368
You can do a little adjustment to leave a blank line at the top.
Like this.
<script type="text/javascript" >
alert("USER NOTICE " +"\n"
+"\n"
+"New users are not allowed to work " +"\n"
+"with that feature.");
</script>
Upvotes: 4
Reputation: 8624
To answer the questions in terms of how you asked it.
This is actually REALLY easy (in Internet Explorer, at least), i did it in like 17.5 seconds.
If you use the custom script that cxfx provided: (place it in your apsx file)
<script language="VBScript">
Sub myAlert(title, content)
MsgBox content, 0, title
End Sub
</script>
You can then call it just like you called the regular alert. Just modify your code to the following.
Response.Write("<script language=JavaScript> myAlert('Message Header Here','Hi select a valid date'); </script>");
Hope that helps you, or someone else!
Upvotes: 5
Reputation: 49
There's quite a nice 'hack' here - https://stackoverflow.com/a/14565029 where you use an iframe with an empty src to generate the alert / confirm message - it doesn't work on Android (for security's sake) - but may suit your scenario.
Upvotes: 4
Reputation: 187030
No, it is not possible. You can use a custom javascript alert box.
Found a nice one using jQuery
jQuery Alert Dialogs (Alert, Confirm, & Prompt Replacements)
Upvotes: 67
Reputation: 129
Override the javascript window.alert() function.
window.alert = function(title, message){
var myElementToShow = document.getElementById("someElementId");
myElementToShow.innerHTML = title + "</br>" + message;
}
With this you can create your own alert()
function. Create a new 'cool' looking dialog (from some div elements).
Tested working in chrome and webkit, not sure of others.
Upvotes: 12
Reputation: 21
Yes you can change it. if you call VBscript function within Javascript.
Here is simple example
<script>
function alert_confirm(){
customMsgBox("This is my title","how are you?",64,0,0,0);
}
</script>
<script language="VBScript">
Function customMsgBox(tit,mess,icon,buts,defs,mode)
butVal = icon + buts + defs + mode
customMsgBox= MsgBox(mess,butVal,tit)
End Function
</script>
<html>
<body>
<a href="javascript:alert_confirm()">Alert</a>
</body>
</html>
Upvotes: 1
Reputation: 41882
You can do this in IE:
<script language="VBScript">
Sub myAlert(title, content)
MsgBox content, 0, title
End Sub
</script>
<script type="text/javascript">
myAlert("My custom title", "Some content");
</script>
(Although, I really wish you couldn't.)
Upvotes: 36