Connecting Tech Pros Worldwide Forums | Help | Site Map

Displaying upper ASCII (code 128-255) in alert() window.

hugo2
Guest
 
Posts: n/a
#1: Jul 23 '05
Most of these characters are not on the standard keyboard.
Here's a successful contrivance, with comments & cautions,
a little page that works in IE6.

<HTML><HEAD><SCRIPT TYPE="text/javascript">
function alt() {
document.all.s1.innerHTML="Current Temp: 68°F";
var txt=document.all.s1.innerText;
alert(txt);
}
</SCRIPT></HEAD>
<BODY>
<INPUT TYPE="button" VALUE="Temperature" onClick="alt()">
<P ID="s1" STYLE="visibility:hidden"> </P>
</BODY></HTML>

comments: The innerHTML property is needed to produce the
character glyph from the entity code. If the entity string
were passed to innerText(in 1st statement) then the code
would remain literal.
This work-around depends on s1 being rendered before alt()
is called. It will not work as immediately executed code,
because element s1 would not exist yet.

cautions: Trying to style alert's display will produce error
msgs. Do not use <B>, <U>, or <I> tags in the argument
string. No Heading tags either.
Strange enough, an inline STYLE, setting font values, say,
does not give error msg, but will not execute either.
Alert ignores it.
You can use <BR> tags in the argument, which give the same
result as \n in a direct arg to alert().

In sum, you can tell alert what characters to display,
in what order, and on what line, but you cannot tell
alert HOW to display them.

hugo2, March 4, 2005




Randy Webb
Guest
 
Posts: n/a
#2: Jul 23 '05

re: Displaying upper ASCII (code 128-255) in alert() window.


hugo2 wrote:
[color=blue]
> Most of these characters are not on the standard keyboard.
> Here's a successful contrivance, with comments & cautions,
> a little page that works in IE6.[/color]

Define "works". It does not "work" for me in IE6 on WinXP SP2.

Before posting code, you should at minimum validate the HTML and test it.
[color=blue]
> <HTML><HEAD><SCRIPT TYPE="text/javascript">
> function alt() {
> document.all.s1.innerHTML="Current Temp: 68°F";[/color]

IE only.
[color=blue]
> var txt=document.all.s1.innerText;[/color]

IE only.
[color=blue]
> alert(txt);
> }[/color]

function oneThatWorks(){
document.getElementById('s1').innerHTML="Current Temp: 68°F";
var txt= document.getElementById('s1').innerHTML;
alert(txt);
}

Now, it is tested to work in IE6, Opera 7 and Mozilla.
[color=blue]
> </SCRIPT></HEAD>
> <BODY>
> <INPUT TYPE="button" VALUE="Temperature" onClick="alt()">[/color]

Object does not support this method.

As reported by IE6 when given a strict doctype.
[color=blue]
> <P ID="s1" STYLE="visibility:hidden"> </P>
> </BODY></HTML>
>
> comments: The innerHTML property is needed to produce the
> character glyph from the entity code. If the entity string
> were passed to innerText(in 1st statement) then the code
> would remain literal.
> This work-around depends on s1 being rendered before alt()
> is called. It will not work as immediately executed code,
> because element s1 would not exist yet.[/color]

See above. Reading this groups FAQ will show you how to insert, and
read, text from a div tag in most major browsers without resorting to IE
only code, even though it uses the semi-proprietary (non-standard) innerHTML
[color=blue]
> cautions: Trying to style alert's display will produce error
> msgs. Do not use <B>, <U>, or <I> tags in the argument
> string. No Heading tags either.[/color]

Who told you that garbage?

alert('This has a <B>, a <U> and an <I> tag in it, test it!')
[color=blue]
> Strange enough, an inline STYLE, setting font values, say,
> does not give error msg, but will not execute either.
> Alert ignores it.[/color]

Thats because you can't "style" an alert. If you want style, write your
own alert div tag in the page.
[color=blue]
> You can use <BR> tags in the argument, which give the same
> result as \n in a direct arg to alert().[/color]

BULL. Test before you post.

alert('This has a <BR> tag but no line break in the alert, test it!')

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Answer:It destroys the order of the conversation
Question: Why?
Answer: Top-Posting.
Question: Whats the most annoying thing on Usenet?
bumbleguppy
Guest
 
Posts: n/a
#3: Jul 23 '05

re: Displaying upper ASCII (code 128-255) in alert() window.




The easiest way to display characters not on the keyboard is simply:

alert('Current Temp: 68' + String.fromCharCode(176));

hugo2
Guest
 
Posts: n/a
#4: Jul 23 '05

re: Displaying upper ASCII (code 128-255) in alert() window.



Randy Webb wrote:[color=blue]
> hugo2 wrote:
>[color=green]
> > Most of these characters are not on the standard keyboard.
> > Here's a successful contrivance, with comments & cautions,
> > a little page that works in IE6.[/color]
>
> Define "works". It does not "work" for me in IE6 on WinXP SP2.
>
> Before posting code, you should at minimum validate the HTML and test[/color]
it.[color=blue]
>[color=green]
> > <HTML><HEAD><SCRIPT TYPE="text/javascript">
> > function alt() {
> > document.all.s1.innerHTML="Current Temp: 68°F";[/color]
>
> IE only.
>[color=green]
> > var txt=document.all.s1.innerText;[/color]
>
> IE only.
>[color=green]
> > alert(txt);
> > }[/color]
>
> function oneThatWorks(){
> document.getElementById('s1').innerHTML="Current Temp: 68°F";
> var txt= document.getElementById('s1').innerHTML;
> alert(txt);
> }
>
> Now, it is tested to work in IE6, Opera 7 and Mozilla.
>[color=green]
> > </SCRIPT></HEAD>
> > <BODY>
> > <INPUT TYPE="button" VALUE="Temperature" onClick="alt()">[/color]
>
> Object does not support this method.
>
> As reported by IE6 when given a strict doctype.
>[color=green]
> > <P ID="s1" STYLE="visibility:hidden"> </P>
> > </BODY></HTML>
> >
> > comments: The innerHTML property is needed to produce the
> > character glyph from the entity code. If the entity string
> > were passed to innerText(in 1st statement) then the code
> > would remain literal.
> > This work-around depends on s1 being rendered before alt()
> > is called. It will not work as immediately executed code,
> > because element s1 would not exist yet.[/color]
>
> See above. Reading this groups FAQ will show you how to insert, and
> read, text from a div tag in most major browsers without resorting to[/color]
IE[color=blue]
> only code, even though it uses the semi-proprietary (non-standard)[/color]
innerHTML[color=blue]
>[color=green]
> > cautions: Trying to style alert's display will produce error
> > msgs. Do not use <B>, <U>, or <I> tags in the argument
> > string. No Heading tags either.[/color]
>
> Who told you that garbage?
>
> alert('This has a <B>, a <U> and an <I> tag in it, test it!')
>[color=green]
> > Strange enough, an inline STYLE, setting font values, say,
> > does not give error msg, but will not execute either.
> > Alert ignores it.[/color]
>
> Thats because you can't "style" an alert. If you want style, write[/color]
your[color=blue]
> own alert div tag in the page.
>[color=green]
> > You can use <BR> tags in the argument, which give the same
> > result as \n in a direct arg to alert().[/color]
>
> BULL. Test before you post.
>
> alert('This has a <BR> tag but no line break in the alert, test it!')
>
> --
> Randy
> comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup[/color]
weekly[color=blue]
> Answer:It destroys the order of the conversation
> Question: Why?
> Answer: Top-Posting.
> Question: Whats the most annoying thing on Usenet?[/color]

hugo2 March 7, 2004
My apologies to everyone. The one problem with my post
is the function name: alt(). This one name does not work
(I had use several different names) because *alt* turns
out to be an HTML attribute, a rather obscure one in <IMG>,
but I should have checked!
All the other statements I made were derived from testing,
and they are all true, in the context of passing an HTML
fragment containing non-keyboard glyph to alert().
I was not talking about general use of alert().
If interested parties would change the function name to
at() or atl() or go(), then the page works fine,
though you would have to adapt it for other browsers.

hugo2 --

Randy Webb
Guest
 
Posts: n/a
#5: Jul 23 '05

re: Displaying upper ASCII (code 128-255) in alert() window.


hugo2 wrote:[color=blue]
> Randy Webb wrote:
>[/color]

<snip>
[color=blue][color=green]
>>function oneThatWorks(){
>>document.getElementById('s1').innerHTML="Curre nt Temp: 68°F";
>>var txt= document.getElementById('s1').innerHTML;
>>alert(txt);
>>}
>>
>>Now, it is tested to work in IE6, Opera 7 and Mozilla.[/color][/color]

<snip>
[color=blue]
> If interested parties would change the function name to
> at() or atl() or go(), then the page works fine,
> though you would have to adapt it for other browsers.[/color]

No need, I gave one that works (and tested) in IE6, Opera 7 and Mozilla,
so its just a matter of copy/paste. Although mine could stand a little
more feature detection before relying on getElementById and innerHTML
(although there has been no definitive test to ensure that changing an
elements innerHTML property actually changes it's visual appearance).

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Closed Thread