JavaScript - Change the Alert title - Asked By mostafa hamdy on 19-Jan-12 07:06 AM

Hello all
I have some javascript function which contains some alerts , and I want to set some title to this alert according to the alert message an time , how can I do that? please if any body get what I mean and can help me please send me or tell me about some URL may help me in doing that
Regards
Mostafa
smr replied to mostafa hamdy on 19-Jan-12 07:08 AM
hi

no you can't.

Its a security/anti-phishing feature

smr replied to mostafa hamdy on 19-Jan-12 07:08 AM
hi

The title of an alert box cannot be set. You could create a custom alert box, in reality it's just another page, and open it using window.open(), size the window and send your title and text in the querystring.

example:

CustomAlert('Message Message, etc...', 'My Title');

Function CustomAlert(msg, title) {

 if (msg && title) {

  var win = window.open('/path/to/box.aspx?msg=' + msg + '&title=' + title, 'alert box', 'toolbar,width=100px,height=200px');

 }

}

look here for the available features (3rd param in window.open()):

http://www.devguru.com/Technologies/ecmaScript/quickref/win_open.html

D Company replied to mostafa hamdy on 19-Jan-12 07:13 AM
Hello Friend,

Directly you cant edit alert window, to achieve your goal you can create your on message window

sample code on JS

<!--
function CONFIRM(){if (!confirm
("Change this to your message"))
history.go(-1);return " "}
document.writeln(CONFIRM())
<!-- END -->
</SCRIPT>


Regards
D
dipa ahuja replied to mostafa hamdy on 19-Jan-12 07:14 AM

Using JavaScript simple alert box :

Page.RegisterClientScriptBlock("""<script>alert('Book Added');</script>");

Response.Write("<script>alert('Book Added')</script>");

Or you can display your own window by

using the modalpopupExtender:

CSS Effect

----------

<style type="text/css">

  .modalBackground

  {

  background-color#CCCCFF;

  filteralpha(opacity=40);

  opacity0.5;

  }

  .ModalWindow

  {

  bordersolid1px#c0c0c0;

  background-color#99ccff;

  padding0px10px10px10px;

  positionabsolute;

  top-1000px;

  }

</style>

ModapPopUp Code

------------------------

<cc1:ModalPopupExtender TargetControlID="Button2" BackgroundCssClass="modalBackground"

CancelControlID="btnMsg" PopupControlID="Panel1" PopupDragHandleControlID="btnMsg"

ID="ModalPopupExtender2" runat="server">

</cc1:ModalPopupExtender>

<asp:Panel ID="Panel1" runat="server" CssClass="ModalWindow">

<%--Button popup--%>

<center>

<table runat="server">

<tr>

  <td bgcolor="#cccccc" style="border: 1px; border-color: Black;" height="20px" align="left"

  valign="top">

  <div style="border-bottom-width: 1px; border: 1px solid">

  Deletion</div>

  </td>

</tr>

<tr>

  <td align="center" bgcolor="#99ccff">

  <br />

  The Record has been deleted!

  </td>

</tr>

</table>

<asp:Button ID="btnMsg" runat="server" Text="OK" /><br />

</center>

</asp:Panel>

<asp:Button ID="Button2" runat="server" Text="OK" /><br />



mostafa hamdy replied to D Company on 19-Jan-12 07:32 AM
thanx Dear
but I couldnt understand what u mean may u give me more clarification please
regards
Mostafa
Jitendra Faye replied to mostafa hamdy on 19-Jan-12 07:48 AM
You can't change the title  for alert window. but you can use your own popup control.

use jquery popup for this-

after adding jqueryui plugin you can use it.

like this-

<


script>

function

funShow() {

$('#dialog).dialog({ resizable: false, height: 140, modal: true });

}

</



script>


<



div id="dialog" title="Basic dialog">

  PUT YOur control here


</div>


<



asp:Button ID="Button1" runat="server" Text="Button" onClientClick="return funShow()" />



Note- This will be closed when you will click on close button,

Try this and let me know.