简体   繁体   中英

Javascript strings not supporting special characters

I have an HTA with 3 frames which overall looks like this:

<html>
<head>
<script type="text/javascript">
     function f(){
          frames["toolbar"].document.write("Toolbar");
          frames["statusbar"].document.write("Status bar");
     }
</script>
<frameset rows="65,*,19" onload="f()">
     <frame src="about:blank" name="toolbar" application="yes"/>
     <frame src="url.html" name="main" application="yes"/>
     <frame src="about:blank" name="statusbar" application="yes"/>
</frameset>
</html>

Note: The content of the toolbar and statusbar frames are more complicated than what's specified here.

Notice that two frames are defined using JavaScript and don't have a real URL.

Since this HTA is in Swedish, i need to use Swedish special letters which are å, ä and ö, for example alert("Du är inte uppkopplad") . The problem is that in the toolbar frame and in the statusbar frame which the content has been defined in JavaScript, this alert box looks like this: 在此处输入图片说明

It replaces ä with an ugly square in the toolbar frame and in the statusbar frame, but not in the main frame (which has a real URL). How do I fix this?

It works if I create a variable in the parent HTA which takes the value ä like this:

Main HTA:

<html>
<head>
<script type="text/javascript">
     function f(){
          frames["toolbar"].document.write("<script type='text/javascript' src='script.js'><\/script>");
          frames["statusbar"].document.write("Status bar");
     }
     var a = "ä"
</script>
<frameset rows="65,*,19" onload="f()">
     <frame src="about:blank" name="toolbar" application="yes"/>
     <frame src="url.html" name="main" application="yes"/>
     <frame src="about:blank" name="statusbar" application="yes"/>
</frameset>
</html>

script.js:

alert("Du " + parent.a + "r inte uppkopplad");

Thanks to t.niese for giving me the idea in a comment.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM