Hi
JDL said:
I was hoping someone could tell me how formatting of text is done in JS.
There is no such thing like formatting in JavaScript. The text is rendered by the browsers and the formatting understood by the browser is HTML. If your JavaScript code makes the browser to render a string and that string contains HTML markup, the rendered text will look accordingly.
For example the following will replace the current document's first [tt]h1[/tt] element's
(*) text to "I am a formatted heading", where the word "formatted" is written in italic :
[small](*) For the sake of simplicity I supposed at least one such element exists.[/small]
JavaScript:
document[teal].[/teal][COLOR=darkgoldenrod]getElementsByTagName[/color][teal]([/teal][green][i]'h1'[/i][/green][teal])[[/teal][purple]0[/purple][teal]].[/teal]innerHTML[teal]=[/teal][green][i]'I am a <i>formatted</i> heading'[/i][/green]
JDL said:
More specifically, I am trying to use this JS popup window
Define "
JS popup window".
Popup usually means browser window opened with the [tt]window.open()[/tt] method. As such thing is just a regular browser window, it can display any HTML. You can even open the window empty
(**) and generate the document with JavaScript :
[small](**) Tested in latest Gecko, may fail in other browsers/versions due to
Same origin policy.[/small]
JavaScript:
[b]var[/b] win[teal]=[/teal]window[teal].[/teal][COLOR=darkgoldenrod]open[/color][teal]()[/teal]
win[teal].[/teal]document[teal].[/teal][COLOR=darkgoldenrod]open[/color][teal]()[/teal]
win[teal].[/teal]document[teal].[/teal][COLOR=darkgoldenrod]writeln[/color][teal]([/teal][green][i]'<h1>I am another <i>formatted</i> heading</h1>'[/i][/green][teal])[/teal]
win[teal].[/teal]document[teal].[/teal][COLOR=darkgoldenrod]close[/color][teal]()[/teal]
Note that browsers may be set to block popup windows or to open them in tab instead.
If you were thinking to the [tt]window.alert()[/tt] method, its text can not be formatted. The most you can do is to wrap ( with [tt]\n[/tt] ) and align ( with [tt]\t[/tt] ) it.
If you want something like the [tt]window.alert()[/tt] method but with the ability to display HTML formatted text, you will have to use a dedicated JavaScript solution ( or write your own ), which actually formats a regular HTML element to mimic a window. For example you could use
jQuery MsgBox :
HTML:
[b]<link[/b] [maroon]rel[/maroon][teal]=[/teal][green][i]"stylesheet"[/i][/green] [maroon]type[/maroon][teal]=[/teal][green][i]"text/css"[/i][/green] [maroon]href[/maroon][teal]=[/teal][green][i]"jquery.msgbox.css"[/i][/green] [b]/>[/b]
[b]<script[/b] [maroon]type[/maroon][teal]=[/teal][green][i]"text/javascript"[/i][/green] [maroon]src[/maroon][teal]=[/teal][green][i]"jquery.min.js"[/i][/green][b]></script>[/b]
[b]<script[/b] [maroon]type[/maroon][teal]=[/teal][green][i]"text/javascript"[/i][/green] [maroon]src[/maroon][teal]=[/teal][green][i]"jquery.msgbox.min.js"[/i][/green][b]></script>[/b]
JavaScript:
$[teal].[/teal][COLOR=darkgoldenrod]msgbox[/color][teal]([/teal][green][i]'I am <i>formatted</i> message'[/i][/green][teal])[/teal]
Feherke.
[link feherke.github.com/]
[/url]