How to edit a JavaScript alert box title?

How to edit a JavaScript alert box title?

I’m generating a JavaScript alert with following code in C# .NET page:
Response.Write(““);

It displays an alert box with the heading title as “Message from webpage”.
Is it possible to modify the title?

Solutions/Answers:

Solution 1:

No, you can’t.

It’s a security/anti-phishing feature.

Solution 2:

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)

Solution 3:

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.)

Solution 4:

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.

Solution 5:

I Found this Sweetalert for customize header box javascript.

Related:  Large numbers erroneously rounded in 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");
});

Solution 6:

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.