Special chars (æøå): aspx.vb vs. js

H

hansiman

If I add special characters (æøå) to an aspx page in the code behind:

chkBox.Attributes("onclick") = "alert('æøå')

the characters displays just fine.

However, if I place the same characters in a javascript file which I
then reference in the html part of the aspx file:

<script language="javascript" src="tools..js"></script>

the same charters display as "garbage" and I have to use other
characters to have æøå correctly displayed:

æ = æ
ø = ø
å = Ã¥

What is the explanation for this?

/Morten
 
P

Patrice

What is the encoding ? It's likely you render UTF8 HTML code but you didn't
save the js file as a UTF8 file... Try to save the file as utf8.

Patrice
 
H

hansiman

I'm not sure what you mean...

My html file looks like this:

<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="default.aspx.vb" Inherits="mrs._default1"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<HTML>
<HEAD>
<title></title>
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
<LINK href="styles.css" type="text/css" rel="stylesheet">
<script language="javascript" src="tools.js"></script>

My tools.js file is just a plain text file with a js file extensen.

?

/Morten
 
P

Patrice

Try to open the jscript file with notepad and save it using the UTF-8
encoding. You should be able to do this also using VS.NET ("Save as" and you
should have some options to do this).

For now it looks like to me that :
- the HTML content is utf8 encoded (this is in the web.config and added to
an HTTP header)
- the browser assumes then that the jscript file is utf8 encoded

As this is a good old ANSI file it will choke on special characters that are
not encoded the same way using ANSI or UTF-8. Saving the jscript file in
utf8 will ensure compatibility.

I'm not sure but you could have also an attribute at the script tag level
that allows to specify what is the coding of the jscript file (likely be
default assumed to be the same than the web page).

Hope I clarified a bit my thoughts ;-)

Patrice

--
 
H

hansiman

Thanks for the explanation, it works.

Kind of strange as I added the .js file useing vs.net!

/Morten
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top