Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
116
rated 0 times [  117] [ 1]  / answers: 1 / hits: 18010  / 15 Years ago, fri, august 28, 2009, 12:00:00

Is it possible to display superscripted characters (not only numbers) in the alert(), confirm() or prompt() dialogue boxes in JavaScript?



Due to some reasons I need to insert a text:



2 followed by superscripted 'n'
2^n



Into JavaScript alert, confirm and prompt boxes. Fast google searching did help but not exactly I found a way to display superscripted numbers in dialogue boxes using Unicode u00B character but it doesn't work with characters



alert('2u00B2'); shows correctly 2^2
alert('2u00Bn'); shows 2u00Bn


So the goal is to show a character superscripted not the number.






^ is used as Power and to show that next character is superscripted, just in case someone gets confused.


More From » unicode

 Answers
8

There's nothing magical about that character code - it just happens to be the one picked for the Superscript two character. There's also a Superscript three (u00B3) (³) a Superscript one (0B9) (¹), and a Superscript Latin Small Letter N (u207F) (ⁿ). But if you need some other superscript, you're out of luck - alert() doesn't render HTML, so you're limited to the characters defined by Unicode.



You might be better off abandoning alert() entirely, and simulating a modal dialog within the page itself. Many libraries exist to provide this functionality already, including the excellent jQuery UI Dialog.


[#98806] Tuesday, August 25, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
alfonsok

Total Points: 386
Total Questions: 101
Total Answers: 90

Location: Puerto Rico
Member since Sun, Jun 27, 2021
3 Years ago
;