admin 管理员组

文章数量: 1086019

I am developing a web application using PHP,Smarty for a french client. I am facing a problem in java script alert and confirm boxes. How can I use HTML special characters in javascript message boxes. This is my code

<script type="text/javascript">
    function delConfirm(key){

        if(confirm('&Ecirc;tes vous certain de vouloir supprimer ce client ?')){
            window.location = "deleteClient.php?e="+key;
        }

    }
</script>

This is the page source of the first part of the page. Please take a look at the encoding section too,

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="Sunil">

I am developing a web application using PHP,Smarty for a french client. I am facing a problem in java script alert and confirm boxes. How can I use HTML special characters in javascript message boxes. This is my code

<script type="text/javascript">
    function delConfirm(key){

        if(confirm('&Ecirc;tes vous certain de vouloir supprimer ce client ?')){
            window.location = "deleteClient.php?e="+key;
        }

    }
</script>

This is the page source of the first part of the page. Please take a look at the encoding section too,

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="Sunil">
Share Improve this question edited Feb 2, 2013 at 15:53 Technosavia asked Feb 2, 2013 at 15:41 TechnosaviaTechnosavia 852 silver badges12 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 7

That's correct, because confirm doesn't accept HTML. You can use unicode escape sequence in JavaScript, though. You can look up Unicode code point values here. The equivalent of &Ecirc; is U+00CA (it's on this chart), so:

if(confirm('\u00CAtes vous certain de vouloir supprimer ce client ?')){
    window.location = "deleteClient.php?e="+key;
}

Alternately, ensure that your file is correctly encoded (in UTF-8 for example), that your editor understands files encoded in that way, and that the file is served correctly (the server tells the browser it's UTF-8), maybe even throw in a meta charset="xxx" tag in the header for luck, and you can just type the French characters directly into the file.

Use this instead

<script type="text/javascript">
    function delConfirm(key){

        if(confirm('\u00CAtes vous certain de vouloir supprimer ce client ?')){
            window.location = "deleteClient.php?e="+key;
        }

    }
</script>

本文标签: javascriptHTML special characters are not showing properly in jsStack Overflow