Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2224
  • Last Modified:

Formatting of text given as input to the JavaScript alert function

Hello,

Does anybody know if it's possible to format what gets displayed when calling the alert method - eg. if I wanted some part of the text written in red?

Regards
JB
0
JohnBak
Asked:
JohnBak
1 Solution
 
ZylochCommented:
As far as I know, it is impossible to format anything in alert(). The closest you could get is some sort of <div> or a new window that is styled to look like an alert box.

Of course, if you wanted for IE, you could use showModalDialog: http://www.webreference.com/js/column90/index.html
0
 
vbandaruCommented:
i.e is right. You cannot make the alert box itself red, However you can create something so close to the alert box using the modaldialogbox.
0
 
viveksgCommented:
Yeah, no such formatting in alert box. But you can split your message into two lines by adding \n between the words.

e.g: alert("My first line\nMy second line");
0
 
rama_krishna580Commented:
Try this example:

<html>
<head>

<script>
function stylealert(){
placement.innerHTML=message.newalert.value
}
</script>

</head>
<body>

<form name="message">

<!-- PUT YOUR ALERT AS A FIXED SIZED DIV INSIDE THIS CSS-HIDDEN TEXTAREA -->

<textarea name="newalert" style="visibility:hidden">
<div style="width:256px; height:170px; background-color:yellow; border:solid
1px black;"onClick="this.style.visibility='hidden'">
<br>
<center>
<b>
A new kind of alert box
</b>
<br>
<br>
<br>
Click to Close
</center>
</div>
</textarea>

<input type="button" value="Click for alert" onClick="stylealert()">
</form>

<!-- IF YOU WANT TO POSITION THE ALERT DIV USE CSS - position:absolute;
left:Xpx; top:Xpx -->
<!-- OR USE JAVASCRIPT TO DETERMINE THE CENTER OF THE SCREEN-->
<a name="placement"></a>

</body>
</html>

R.K
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now