Quiet Storm
08-01-2002, 02:23 AM
I know the \n trick, but is there a way to center the text that's in an alert box?
|
||||
Is it possible to center text in an Alert box?Quiet Storm 08-01-2002, 02:23 AM I know the \n trick, but is there a way to center the text that's in an alert box? jkd 08-01-2002, 02:31 AM Not really. If you know the amount of characters until it wraps, then possibly, but testing in Moz 1.1b+, the alert box's width grows to accomadate text on one line. Philip M 08-01-2002, 06:54 PM I think     will do the trick. That was supposed to be &nobreakspace &nobreakspace joh6nn 08-01-2002, 07:27 PM i use \t, which is a tab. i figure out how many characters i'm going to use on a line, then encase the text in \t 's. eg: \tThis text will be centered\t\n \tin the middle of the alert\t it's not perfect, but it's as close as i ever got. boxer_1 08-01-2002, 07:29 PM Joh6nn, just to avoid confusion, I deleted my post while you were posting because I decided it was an invalid solution and not worth keeping in place ;). RadarBob 08-01-2002, 09:07 PM Below is the code I was playing with. My conclusion... The non-fixed pitch font used won't allow the text to properly center. Is it possible to change the font type to courier? P.S. I used a "." instead of " " so I could see where blanks are being inserted <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>Centering a Message in an Alert Box</title> <script language="JavaScript" type="text/javascript"> <!-- function cutString (theString, lineWidth) { var endindex = lineWidth; var MessageFrag = new String(); var RemainingFrag = new String(); var padding = 0; if (theString.length <= lineWidth) { MessageFrag = theString; padding = Math.ceil((lineWidth - MessageFrag.length) / 2); for (var i=1; i<= padding; i++) { MessageFrag = " " + MessageFrag; } alert ("hit bottom!. Return now"); return (MessageFrag); } while (theString.charAt(endindex) != " ") { endindex--; } MessageFrag = theString.substring(0,endindex); RemainingFrag = theString.substring(endindex+1, theString.length); padding = Math.ceil((lineWidth - MessageFrag.length) / 2); for (var i=1; i<= padding; i++) { MessageFrag = "." + MessageFrag; } MessageFrag += "\n" + cutString(RemainingFrag, lineWidth); alert ("returning with:\n" + MessageFrag); return (MessageFrag); } // fuction cutString(); //--> var message = new String("Here is a message that I want displayed, centered inside of an alert box. Will it work!?"); var lineLength = 25; var centeredString = new String(); alert ("Here is the original string: \n" + message + "\nlinelength = " + lineLength); centeredString = cutString(message, lineLength); alert ("Here it is centered:\n" + centeredString); </script> </head> <body> </body> </html> Quiet Storm 08-01-2002, 09:12 PM Originally posted by joh6nn i use \t, which is a tab. i figure out how many characters i'm going to use on a line, then encase the text in \t 's. eg: \tThis text will be centered\t\n \tin the middle of the alert\t it's not perfect, but it's as close as i ever got. That works for me! Thanks! :) |
| |||
EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum