473,811 Members | 3,924 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1919
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.javas cript message <t-6dnaW8FJXo4onUn Z2dneKdnZydnZ2d @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.demo n.co.uk/asciihex.txtabo ut 3.5kB.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demo n.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+numer ic 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.fromChar Code(ent[i]));
str = str.replace(/(&)(#)(\d{1,})( ;)/g,
function (tot,amp,cr,cp, sem) {
return String.fromChar Code(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
2119
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 is my code that generates the string : function InvokeURL(url_to_forward_to) { try {
99
6257
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 small or mid-sized business. http://groups-beta.google.com/group/microsoft.public.msdn.general/browse_thread/thread/9d7e8f9a00c1c7da/459ca99eb0e7c328?q=%22Proposed+MSDN+subscription+changes%22&rnum=1#459ca99eb0e7c328 Damn! To be that...
10
13466
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 related to checkboxes. Thanks!!!
1
3570
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 others to "display: block". The problem I am encountering is that when the JavaScript interpreter starts up initially, all style.displays are null. Thus the following code is not effective: function toggleAll(itemname) {
1
2431
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 I'm looking for. I'm looking for a content management system to use on a site (http://www.nigeriavillagesquare.com) that I help to moderate. Unfortunately (as I have discovered), there are literally hundreds of CMS's to choose from, so I am...
11
3491
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 user to save to disk. How can I do this? Thanks, T
5
5052
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 that calls the web service to render a vertical strip of images. After doing some research I am unable to find some vb.net code that can assist in what I want to achieve. The closest thing I found was
4
5629
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 FireFox and Safari it appears as a narrow column of text with only 2-3 words per line. Here is the code: function showAll()
7
8734
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 remain the same. I am interested to know your opinions/suggestions in finding an easy way of doing it. In asp one could have something like this:
0
9604
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10644
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10394
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9201
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7665
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5552
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5690
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4336
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3863
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.