Character encoding changes after window.open()

回眸只為那壹抹淺笑 提交于 2019-12-10 13:43:58

问题


The site from where I'm calling the window.open() function is in UTF-8, using the <meta> tag, everything works well, but once I call the function and open another window with the same tag, the new window shows weird characters even thought in page info it shows that the encoding stays the same (UTF-8).

This is the same problem as mine: http://bytes.com/topic/javascript/answers/622922-character-encoding-after-window-open


回答1:


I had exactly the same problem.

Problem turned out to be that I was setting "Session.CodePage = 65001" in the window opened. That screwed up the character encoding for that session. So when I refreshed the "main" page, some characters (such as åäö) were suddenly garbled.

Solution: make sure the page in the new window doesn't change the session's code page. Good luck!




回答2:


I had the same problem. Just use unescape(decodeURIComponent( YOUR_URL )) inside window.open().

For example: window.open(unescape(decodeURIComponent( YOUR_URL )), '_blank');

Hope it helps.




回答3:


Add a charset="UTF-8" attribute to your javascript tags. This will at least work if the cause of the garbled characters is your included javascript.




回答4:


If the browser uses the same encoding for both pages (which, apparently, it does) then the problem must be in the page itself. It probably contains invalid UTF-8 to begin with.



来源:https://stackoverflow.com/questions/2140310/character-encoding-changes-after-window-open

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!