views:

5311

answers:

4

Hi, 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?

+9  A: 

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)

rahul
Thank u ,but i am not interested in using custom alert box
subash
@subash: game over, then.
just somebody
The reason you can't change the title, by the way, is to prevent malicious web sites from tricking the user into thinking the alert is from their OS or something else.
benzado
+4  A: 

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

cxfx
We all wish the same
rahul
+4  A: 

Sigh...no you can't

Pierreten
A: 

To answer the questions in terms of how you asked it.

This is actually REALLY easy, 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!

kralco626
Works for me with IE, but not Firefox. Thanks just the same, quick and dirty but might prove useful.
Darth Continent
@ Darth. Yo I proly should have mentioned that. Its using VBScript. you have have to google how to get VBScript to run in firefox.
kralco626
@ Dath - PS I don't know if there is a way to possibly run VBScript on firefox. I would create another topic called something like how to run this vb script in firefox and post the code I gave you above and see if anyone can come up with anything.
kralco626
@Darth - Although I would use Rahul's solution. Just use some JQuery it's really easy!
kralco626
Thanks, I tried out a couple of JQuery-based alert boxes and they're great.
Darth Continent