2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

microsoft edgeのjavascript文字化け対策

Last updated at Posted at 2019-06-29

edgeにてjavascriptを使用して日本語を挿入した際に文字化けが発生した場合の対処方法

comment_count.js
//コメント欄の文字数をカウントするためのjsです。
$(function(){
    $('.comment').keyup(function(){
        let count = 255 - $(this).val().length;
        $('.comment').text("コメントはあと" + count + "文字入力できます");
        if(count <= 0){
            $('.comment').text("コメントは255文字までです");
        }
    });
});

edge環境でのみ以下のような文字化けが発生
文字化け.PNG

対処方法

1.javascriptをBOM付UTF-8に変換する
(使用ツールはCotEditor)
スクリーンショット 2019-06-30 11.36.16.png

2.javascriptを読み込む時にcharset='UTF-8'を指定する
(順番をcharset, srcの順にしないだめかも)
<script charset='UTF-8' src="comment_count.js"/>

edge環境でも文字化けせず表示されました!
修正後.PNG

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?