473,288 Members | 1,771 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,288 software developers and data experts.

How can I display the content literally without any change?

hi,dear all js gurus.
In my app, server responses some text like: '   [Download
Now]'
and I need display these content in textarea.
But Html would convert specail characters to space, and ignore line
break.

How can I display the content literally without any change?

Any help is greatly appreciated, and Thanks for any reply in advance.
Nov 7 '08 #1
3 1884
yuanyun.ken wrote:
In my app, server responses some text like: '   [Download
Now]'
How can I display the content literally without any change?
I can't say how to do this in JavaScript, but the problem is common to
any programming language. I've found the following sufficient, although
there may be cases that don't work properly (I've never seen any):

1. Convert all "&" characters to "&"
2. Convert all "<" characters to "&lt;"
3. Convert all line breaks to "<BR>"

Notes:

Some will insist that you also translate ">" to "&gt;" after step 2.
I've never found this necessary.

There are at least 3 "line break" sequences that you may encounter,
0x0A, 0x0D and 0x0D0A. If you convert all three then start with 0x0D0A
otherwise you'll end up with two <BRsequences instead of one for each
0x0D0A sequence.

--
Steve Swift
http://www.swiftys.org.uk/swifty.html
http://www.ringers.org.uk
Nov 7 '08 #2
In comp.lang.javascript message <t-6dnaW8FJXo4onUnZ2dneKdnZydnZ2d@bright
view.com>, Fri, 7 Nov 2008 17:48:24, Swifty <st***********@gmail.com>
posted:
>There are at least 3 "line break" sequences that you may encounter,
0x0A, 0x0D and 0x0D0A. If you convert all three then start with 0x0D0A
otherwise you'll end up with two <BRsequences instead of one for each
0x0D0A sequence.

\u0D0A __might__ be paragraph break, but 0x0D0A is 3338; you probably
meant \x0D\x0A.

In addition, Form Feed is \x0C, Vertical Tab is \x0B, and I'd expect
Unicode to have a variety of breaks represented by \u#### but not \x##.

For ASCII, feel free to print
<URL:http://www.merlyn.demon.co.uk/asciihex.txtabout 3.5kB.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/- FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
Do not Mail News to me. Before a reply, quote with ">" or "" (SonOfRFC1036)
Nov 8 '08 #3
Swifty wrote:
yuanyun.ken wrote:
>In my app, server responses some text like: '&nbsp;&nbsp;
[Download Now]'
How can I display the content literally without any change?

I can't say how to do this in JavaScript, but the problem is common to
any programming language. I've found the following sufficient, although
there may be cases that don't work properly (I've never seen any):

1. Convert all "&" characters to "&amp;"
2. Convert all "<" characters to "&lt;"
3. Convert all line breaks to "<BR>"
A bit meagre IMHO; I would prefer a complete list, and perhaps also
the numeric entities.

I once wrote a HTML4 conversion utility for character+numeric entities
(so doesn't handle <BRand the like):

var ent = new Object()
ent['quot'] = 34
ent['amp'] = 38
ent['lt'] = 60
ent['gt'] = 62
ent['nbsp'] = 160
ent['iexcl'] = 161
ent['cent'] = 162
ent['pound'] = 163
ent['curren'] = 164
ent['yen'] = 165
ent['brvbar'] = 166
ent['sect'] = 167
ent['uml'] = 168
ent['copy'] = 169
ent['ordf'] = 170
ent['laquo'] = 171
ent['not'] = 172
ent['shy'] = 173
ent['reg'] = 174
ent['macr'] = 175
ent['deg'] = 176
ent['plusmn'] = 177
ent['sup2'] = 178
ent['sup3'] = 179
ent['acute'] = 180
ent['micro'] = 181
ent['para'] = 182
ent['middot'] = 183
ent['cedil'] = 184
ent['sup1'] = 185
ent['ordm'] = 186
ent['raquo'] = 187
ent['frac14'] = 188
ent['frac12'] = 189
ent['frac34'] = 190
ent['iquest'] = 191
ent['Agrave'] = 192
ent['Aacute'] = 193
ent['Acirc'] = 194
ent['Atilde'] = 195
ent['Auml'] = 196
ent['Aring'] = 197
ent['AElig'] = 198
ent['Ccedil'] = 199
ent['Egrave'] = 200
ent['Eacute'] = 201
ent['Ecirc'] = 202
ent['Euml'] = 203
ent['Igrave'] = 204
ent['Iacute'] = 205
ent['Icirc'] = 206
ent['Iuml'] = 207
ent['ETH'] = 208
ent['Ntilde'] = 209
ent['Ograve'] = 210
ent['Oacute'] = 211
ent['Ocirc'] = 212
ent['Otilde'] = 213
ent['Ouml'] = 214
ent['times'] = 215
ent['Oslash'] = 216
ent['Ugrave'] = 217
ent['Uacute'] = 218
ent['Ucirc'] = 219
ent['Uuml'] = 220
ent['Yacute'] = 221
ent['THORN'] = 222
ent['szlig'] = 223
ent['agrave'] = 224
ent['aacute'] = 225
ent['acirc'] = 226
ent['atilde'] = 227
ent['auml'] = 228
ent['aring'] = 229
ent['aelig'] = 230
ent['ccedil'] = 231
ent['egrave'] = 232
ent['eacute'] = 233
ent['ecirc'] = 234
ent['euml'] = 235
ent['igrave'] = 236
ent['iacute'] = 237
ent['icirc'] = 238
ent['iuml'] = 239
ent['eth'] = 240
ent['ntilde'] = 241
ent['ograve'] = 242
ent['oacute'] = 243
ent['ocirc'] = 244
ent['otilde'] = 245
ent['ouml'] = 246
ent['divide'] = 247
ent['oslash'] = 248
ent['ugrave'] = 249
ent['uacute'] = 250
ent['ucirc'] = 251
ent['uuml'] = 252
ent['yacute'] = 253
ent['thorn'] = 254
ent['yuml'] = 255
ent['OElig'] = 338
ent['oelig'] = 339
ent['Scaron'] = 352
ent['scaron'] = 353
ent['Yuml'] = 376
ent['fnof'] = 402
ent['circ'] = 710
ent['tilde'] = 732
ent['Alpha'] = 913
ent['Beta'] = 914
ent['Gamma'] = 915
ent['Delta'] = 916
ent['Epsilon'] = 917
ent['Zeta'] = 918
ent['Eta'] = 919
ent['Theta'] = 920
ent['Iota'] = 921
ent['Kappa'] = 922
ent['Lambda'] = 923
ent['Mu'] = 924
ent['Nu'] = 925
ent['Xi'] = 926
ent['Omicron'] = 927
ent['Pi'] = 928
ent['Rho'] = 929
ent['Sigma'] = 931
ent['Tau'] = 932
ent['Upsilon'] = 933
ent['Phi'] = 934
ent['Chi'] = 935
ent['Psi'] = 936
ent['Omega'] = 937
ent['alpha'] = 945
ent['beta'] = 946
ent['gamma'] = 947
ent['delta'] = 948
ent['epsilon'] = 949
ent['zeta'] = 950
ent['eta'] = 951
ent['theta'] = 952
ent['iota'] = 953
ent['kappa'] = 954
ent['lambda'] = 955
ent['mu'] = 956
ent['nu'] = 957
ent['xi'] = 958
ent['omicron'] = 959
ent['pi'] = 960
ent['rho'] = 961
ent['sigmaf'] = 962
ent['sigma'] = 963
ent['tau'] = 964
ent['upsilon'] = 965
ent['phi'] = 966
ent['chi'] = 967
ent['psi'] = 968
ent['omega'] = 969
ent['thetasym'] = 977
ent['upsih'] = 978
ent['piv'] = 982
ent['ensp'] = 8194
ent['emsp'] = 8195
ent['thinsp'] = 8201
ent['zwnj'] = 8204
ent['zwj'] = 8205
ent['lrm'] = 8206
ent['rlm'] = 8207
ent['ndash'] = 8211
ent['mdash'] = 8212
ent['lsquo'] = 8216
ent['rsquo'] = 8217
ent['sbquo'] = 8218
ent['ldquo'] = 8220
ent['rdquo'] = 8221
ent['bdquo'] = 8222
ent['dagger'] = 8224
ent['Dagger'] = 8225
ent['bull'] = 8226
ent['hellip'] = 8230
ent['permil'] = 8240
ent['prime'] = 8242
ent['Prime'] = 8243
ent['lsaquo'] = 8249
ent['rsaquo'] = 8250
ent['oline'] = 8254
ent['frasl'] = 8260
ent['euro'] = 8364
ent['image'] = 8465
ent['weierp'] = 8472
ent['real'] = 8476
ent['trade'] = 8482
ent['alefsym'] = 8501
ent['larr'] = 8592
ent['uarr'] = 8593
ent['rarr'] = 8594
ent['darr'] = 8595
ent['harr'] = 8596
ent['crarr'] = 8629
ent['lArr'] = 8656
ent['uArr'] = 8657
ent['rArr'] = 8658
ent['dArr'] = 8659
ent['hArr'] = 8660
ent['forall'] = 8704
ent['part'] = 8706
ent['exist'] = 8707
ent['empty'] = 8709
ent['nabla'] = 8711
ent['isin'] = 8712
ent['notin'] = 8713
ent['ni'] = 8715
ent['prod'] = 8719
ent['sum'] = 8721
ent['minus'] = 8722
ent['lowast'] = 8727
ent['radic'] = 8730
ent['prop'] = 8733
ent['infin'] = 8734
ent['ang'] = 8736
ent['and'] = 8743
ent['or'] = 8744
ent['cap'] = 8745
ent['cup'] = 8746
ent['int'] = 8747
ent['there4'] = 8756
ent['sim'] = 8764
ent['cong'] = 8773
ent['asymp'] = 8776
ent['ne'] = 8800
ent['equiv'] = 8801
ent['le'] = 8804
ent['ge'] = 8805
ent['sub'] = 8834
ent['sup'] = 8835
ent['nsub'] = 8836
ent['sube'] = 8838
ent['supe'] = 8839
ent['oplus'] = 8853
ent['otimes'] = 8855
ent['perp'] = 8869
ent['sdot'] = 8901
ent['lceil'] = 8968
ent['rceil'] = 8969
ent['lfloor'] = 8970
ent['rfloor'] = 8971
ent['lang'] = 9001
ent['rang'] = 9002
ent['loz'] = 9674
ent['spades'] = 9824
ent['clubs'] = 9827
ent['hearts'] = 9829
ent['diams'] = 9830

var str = '&nbsp;&nbsp; &lt; &AmP; a'
for (var i in ent)
str = str.replace(new RegExp('&'+i+';','gi'),
String.fromCharCode(ent[i]));
str = str.replace(/(&)(#)(\d{1,})(;)/g,
function (tot,amp,cr,cp,sem) {
return String.fromCharCode(cp)
}
)
alert(str)

--
Bart
Nov 11 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Rick | last post by:
Hi.. I've got some code I wrote in PHP that will generate a new argument string for the browser, but the xhtml parser in Firefox and Opera both complain about my use of &var=value pairs. Below...
99
by: Jim Hubbard | last post by:
It seems that Microsoft not only does not need the classic Visual Basic developer army (the largest army of developers the world has ever seen), but now they don't need ANY Windows developer at a...
10
by: DettCom | last post by:
Hello, I would like to be able to display or hide fields based on whether a specific Yes/No radio button is selected. This is in conjunction with a posting a just made here in the same group...
1
by: Tristan Miller | last post by:
Greetings. I am trying to write a function which toggles the display of a certain class of <div> elements in an HTML page. The CSS file initially sets some classes to "display: none", and...
1
by: Epetruk | last post by:
Hello all, I'm sorry for the long post, but I think it's better if I'm as detailed as I can be so that I don't make a mistake in my choice and so that there's a clear understanding of to what...
11
by: Tina | last post by:
I'm in a button clicked event on mainpage.aspx. I want to display a new webpage that has just my image, which is a jpg. I want the page to be a ..jpg not an aspx so that it will be easy for the...
5
by: Peter Lapic | last post by:
I have to create a image web service that when it receives an imageid parameter it will return a gif image from a file that has been stored on the server. The client will be an asp.net web page...
4
by: drew197 | last post by:
I am a newbie. I am editing someone elses code to make it compatible with Firefox and Safari. In IE, when you click on the proper link, a block of text is shown in a nice paragraph form. But, in...
7
by: xkeops | last post by:
Thinking of creating a website, most of the pages will have a general toolbar menu, a content and a footer. The content will be the only one who's gonna change but the rest (header,footer) will...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.