Reputation: 85
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('Ê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">
Upvotes: 2
Views: 7603
Reputation: 1074335
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 Ê
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.
Upvotes: 7
Reputation: 3796
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>
Upvotes: 1