/    Sign up×
Community /Pin to ProfileBookmark

Is it possible to format a text that appears on alert() ?

Can I display a bold text on alert () ? if so how?

Thank you

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@felgallMay 06.2007 — Only by changing the system fonts used by the operating system to change the appearance of the text in all of the dialog boxes displayed on that computer.
Copy linkTweet thisAlerts:
@hackmagicMay 06.2007 — hey mesh2005,

the strings passed to the alert() method are unicode strings (see http://msdn2.microsoft.com/en-gb/library/7wkd9z69.aspx).

this means you can theoretically pass the codes rather than the characters but i dont know how to pass the unicode sequence. the unicode values can be found at http://unicode.org/charts/ - english is the latin series of charts.

it would be interesting to see if this works. i dont think there is any support for emboldening though.

to do what you want it would be better to have an alert div and show it with this fn:

function alertDiv(xPos, yPos, message, isVisible)

{

if (isVisible)

{

document.getElementById("alertDiv").style.top=yPos;

document.getElementById("alertDiv").style.left=xPos;

document.getElementById("messageCell").innerHTML=message;

document.getElementById("alertDiv").style.visibility="visible";

}

else

document.getElementById("alertDiv").style.visibility="hidden";

}

HTML:

<p><a onclick="alertDiv(100, 100, '<p><b>Hi</b></p>', true)">click</a></p>

<div id="alertDiv" style="background-color:#CCCCCC; border:1px ridge #CCCCCC; visibility:hidden; width:100px; position:absolute">

<table cellpadding="0" cellspacing="0" border="0" width="100%">

<tr><td style="background-color:#222299"><b>Alert</b></td></tr>

<tr><td id="messageCell" align="center"></td></tr>

<tr><td align="center"><input type="button" value="Ok" onclick="alertDiv(0,0,'', false)"></td></tr>

</table>

</div>

you can play about with the border settings and maybe autocalculate x and y positions from screen width so it always is in center. also to mimic the modal nature of the alert pop-up you could use the Event object and its ability to capture mouseclicks as they bubble up through the heirarchy, and include activation for that code in the alertDiv fn. cant remember how to do it offhand though
Copy linkTweet thisAlerts:
@felgallMay 06.2007 — Unicode iis only an extended character set with more characters than ASCII. it doesn't provide any way of formatting those characters in a specific font, blod, etc. The only way of styling an alert specific to your web page is if you make the alert a part of your page content instead of using the alert() function.
×

Success!

Help @mesh2005 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.4,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...