ray sn0w
ray sn0w

Reputation: 1209

Sweet Alerts is display UTF-8 Chars wrong

I don't know what is wrong, I have this JavaScript function:

<script charset="utf-8" type="text/javascript">
$(document).ready(function(){
    //initialize the javascript
    App.init();
    @if(Session::has('message'))
    var msg = '{{ Session::get('message') }}';
    console.log(msg);
    swal({
        title: "",
        text: 'compa&ntilde;ia',
        type: "warning",
        confirmButtonText: "Ok!",
        closeOnConfirm: false
    });
    $(window).bind("load", function() {
        $.gritter.add({
            title: 'Atencion',
            text: 'compa&ntilde;ia',
            image: '{{ asset('images/clipboard_icon.png') }}',
            class_name: 'danger',
            time: ''
        });
        return false;
    });
    @endif
});
</script>

The problem is that sweet alerts doesn't display: 'compañia' it displays 'compa&ntilde;ia' but the gritter message is correctly displaying the word. (See picture) enter image description here

As you can see the red gritter correctly displays the word, but the sweet alert doesn't,

The file is UTF-8 encoded, so is the meta and the script also just in case, and before you ask why I put 'compa&ntilde;ia' its part of a larger message that is send by Laravel on the session and retrieved by the view in that format.

Anyway my real question is why does the gritted display the word fine and how can I fix it so it works also on sweet alert.

Upvotes: 2

Views: 7872

Answers (2)

Leo
Leo

Reputation: 1505

I fixed it by setting html to the text.

swal({
        title: "",
        text: 'compa&ntilde;ia',
        type: "warning",
        confirmButtonText: "Ok!",
        closeOnConfirm: false,
        html: 'compa&ntilde;ia'
    });

Upvotes: 1

ray sn0w
ray sn0w

Reputation: 1209

I just fixed it by adding html: true to the function:

swal({
        title: "",
        text: 'compa&ntilde;ia',
        type: "warning",
        confirmButtonText: "Ok!",
        closeOnConfirm: false,
        html: true
    });

Upvotes: 8

Related Questions