1

I have a problem concerning string output on HTML page when using Javascript and ASP. Logic of page generation goes like this:

  1. We use asp page to generate HTML code using Response.Write(). If string contains numeric character reference (for example С) it would show on the user's side just fine as a character.

  2. After that we add OnLoad event, which calls for a Javascript function. All this happens inside <body><\body> tags. Source for JavaScript added inside <script></script> tags. The function only adds document.href, which contains reference to the same asp page.

  3. The asp logic loads again and adds some text to the page using Response.BinaryWrite() (Response.Write can be used all the same) All character references are shown as codes:&#1057;. Obviously all '&' symbols become &amp;(asp automatic conversion), browser decodes it as & and we can only see a code &#1057; and not the symbol 'С'.

As far as I know such behaviour can be caused by <script> tags, as a precaution against xss attacks. In the end I want to stop encoding '&' as &amp;.

However here is the most important part:

If I add header with "Content-Type" "text\html", IE (any version) starts encoding NCR symbols in a correct way. But Firefox, Chrome and Safari do not change behavior and keep encoding & as &amp;. I can see several questions on Stack Overflow which looks like mine, yet the situation is not exactly the same (My strings are not inserted directly by JavaScript, so I cannot manipulate output string and change &amp; to &, also my strings have correct symbols in the first place, they get changed by asp or by browser). Is there any elegant way to force Firefox or Chrome to decode page as IE? Maybe some settings or attributes in HTML tags? This problem looks like it depends on a browser to me, am I right?

  • 1
    It's not caused by the ` – Pointy Aug 20 '13 at 13:49
  • Thanks for the answer. Well, I really think it is a combination of ASP restrictions and ` – user2699786 Aug 20 '13 at 13:55
  • There is absolutely nothing about a plain ` – Pointy Aug 20 '13 at 14:02
  • I see. So the only way to correct this problem is to call other ASP function from Response object? – user2699786 Aug 20 '13 at 14:07
  • It's not really clear exactly what the problem is; you have not posted any of the code involved. – Pointy Aug 20 '13 at 14:08
  • If it is happening on the ASP side could you do replace your response.write(YourVariable) with response.write(Replace(YourVariable, "&", "&")) – John Aug 20 '13 at 14:16
  • My variable does not contain & so I think this won't work. – user2699786 Aug 20 '13 at 14:26
  • If the &s are coming out of your Response.Write statement then it should work. Response.Write doesn't automatically convert & to & - you need to use Server.HTMLEncode to do that. If you could post your code it would be much easier to work out what is happening – John Aug 20 '13 at 14:52
  • The problem is that code is pretty complicated: asp methods are called through COM interface and there are a lot of things generated on the page, so without context it is hard to tell what is what. I tried to descripe the problem without posting any actual code because of this. Anyway if we do not post my content but, for example `Response.Write(С)` it would still be `С` on the output. So I cannot see how Replace can help here. – user2699786 Aug 20 '13 at 15:07
  • Also what code is needed? Code of the page which is generated or ASP methods I use to compose the page? – user2699786 Aug 20 '13 at 15:12
  • The ASP/VBScript code which contains the response.write statement which is producing the errors. I've just been experimenting and I think Response.BinaryWrite may be the cause of your problem. Through the Opera btowser <% Response.BinaryWrite("С") %> becomes С while <% Response.Write("С") %> gives C. Similarly Response.BinaryWrite gives & where Response.Write gives &. Also, if I use BinaryWrite and do a View Source I see nothing – John Aug 20 '13 at 16:00
  • I was playing with these functions too, response.write won't help in this situation, problem is not in BinaryWrite. I had a link to a nice asp documentation where it was said, when using ASP automatically converts & to &. I really wish to avoid that. – user2699786 Aug 21 '13 at 14:49

0 Answers0