I get this warning in FF when developing a site of mine. I can't find any real info about it and how to fix this.
the character encoding of a framed document was not declared. The document may appear different if viewed without the document framing it.
...e)});else for(var g in a)ca(g,a[g],c,e);return d.join("&").replace(bD,"+")}}),f....
jquery....min.js (line 4)
You need to put
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
In the head of the iframe or whatever charset encoding you are using.
In your case, it looks like you are serving a javascript file. In order to set the character encoding, you have to set it in the Content-Type HTTP header when serving the javascript file.
E.g:
Content-Type: application/javascript; charset=utf-8
However, if you are using an <iframe> element to reference javascript, then you are doing it wrong.
You should only use an <iframe> to display something, like HTML, text, SVG, PDF etc.
For an HTML document you can, inside the .html file, set the character encoding with a charset attribute on the <meta> tag and on a <script> tag. Note that the latter is deprecated and all modern browsers will read the <meta> tag of the document referencing the script.
Examples
iframed.html
<head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
<script src="jquery....min.js" charset="utf-8"></script>
<!-- note: setting charset on a <script> tag is deprecated -->
</head>
index.html
<body>
<iframe src="iframed.html">
</body>
If you have access to your web server, then you can set the character encoding as part of the response with Content-Type and you do not need to specify it in your documents.
HTML: Content-Type: text/html; charset=utf-8
JS: Content-Type: application/javascript; charset=utf-8
JSON: Content-Type: application/json; charset=utf-8
text: Content-Type: text/plain; charset=utf-8
In nodejs you use the setHeader method on the Response object.
response.setHeader ('Content-Type', 'text/html; charset=utf-8')
DevTools
You can use your browser's DevTools to inspect the network request and check the value of Content-Type header. See screen shot below.
Related
I am facing a strange issue with wkhtmltopdf. While in Footer and Content, all special characters are shown as supposed, in the header file, they don't show up or get replaced by blocks with a question mark. All of the three files are built the same:
<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
</body>
</html>
Is there some kind of trick to tell the header to use utf-8 to?
Btw, I am already telling wkhtmltopdf to use utf-8 not only as meta but also in the script call:
--encoding utf-8
EDIT: I am using an html-header (as you can see on the code I posted). Every 3 HTML files are built the same way. But while it is working in the content, the header don't likes my special chars. Maybe it is a problem that the content in the header comes from a $_POST variable while in the content, the text is built out of the db?
I am still having issues with the black diamonds.
Take a look at this page: http://fpmnky.com/airport.php?airport_id=4131
The characters work great on the page, but in the search box type "LFLB" and you will see that the diamonds show up again.
This is in my header:
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
I also did a mysql_client_encoding() check and it said Latin1.
What else do I need to do?
Use
header("Content-Type: text/html; charset=iso-8859-1");
In the ajax response, or any response in general on your website.
My webpage's response headers show this:
Content-Type:text/html; charset=UTF-8
However, I still get a black diamond with white question mark for characters like é. What am I supposed to do exactly? It's my .htaccess that's setting UTF-8.
If its a script or HTML file, check the encoding of the file itself, which should be saved as UTF-8.
In Zend, its something like: Edit->Set encoding->Other: UTF-8,
If you are serving a HTML page you need to indicate in the HTML file that the content is UTF-8.
You can do this by adding a meta html tag to your header section:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
I the following text (used for testing):
TÄSTåÄ
It's showing on the page as:
T�ST��
I have utf-8 as my content-type:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
I'm using font-family:
"lucida
grande",tahoma,verdana,arial,sans-serif
Any idea why thse characters won't show up properly?
Thank you!
You need to be sure that the file is being saved as a UTF-8 encoded file and not as plain text.
Pls make sure you saved file in 'UTF-8' or 'utf-8 without BOM'. If you used UTF-8 only for encoding your html page, please check the DOCTYPE is valid.
I recently changed some of my pages to be displayed via ajax and I am having some confusion as to why the utf8 encoding is now displaying a question mark inside of a box, whereas before it wasn't.
Fore example. The oringal page was index.php. charset was explicitly set to utf8 and is in the <head>. I then used php to query the database
Heres is the original index.php page:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Title here</title>
</head>
<body class='body_bgcolor' >
<div id="main_container">
<?php
Data displayed via php was simply a select statement that output the HTML.
?>
</div>
However, when I made the change to add a menu that populated the "main_container" via ajax all the utf8 encoding stopped working. Here's the new code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Title here</title>
</head>
<body class='body_bgcolor' >
About Us
<div id="main_container"></div>
The "display_html()" function calls the javascript page which uses jquery ajax call to retrieve the html stored inside a php page, then places the html inside the div with an id of "main_container". I'm setting the charset in jquery to be utf8 like:
$.ajax({
async: false,
type: "GET",
url: url,
contentType: "charset=utf-8",
success: function(data)
{
$("#main_container").html(data);
}
});
What am I doing wrong?
Encoding is more than specifying the meta tag and content type - the files themselves must really be in the encoding you specify, or you'll get mojibake.
Check that everything is using UTF-8, your database, database connection, table columns. Check that any static files you are including are also encoded in UTF-8.
You wrote
The "display_html()" function calls
the javascript page which uses jquery
ajax call to retrieve the html
stored inside a php page
What do you mean with "the html stored inside a php page"? If you want to load data and display there as a contain of <div> the loaded data should be formated correspondent. I mean that it should be real a code fragment of HTML. Moreover Together with 'contentType' it would be a good idea to specify 'dataType' as "html" or "text". If you don't specity anything the last version of jQuery will "intelligently try to get the results, based on the MIME type of the response". If you know the 'dataType', it would be better to specify there. And if you use ajax use also default 'async: true' and not 'false'.
You should also verify whether jQuery.load method (see http://api.jquery.com/load/) is the best choice for you. You can load with the mathod a full html page if required and display only a part of there: $('#main_container').load('ajax/about_us.html #container');
And about UTF-8 encoding don't forget to save the file really UTF-8 encoded. Use corresponding option of your editor (in Notepad choose "Save As" and then choose as encoding "UTF-8" and not "ANSI").
Make sure all your files are saved as UTF-8 (or UTF-8 w.o. BOM).
If you have uploaded them by FTP or with a web tool, check if they are still UTF-8.
In my case neither of the solutions worked until I placed
header('Content-type: text/html; charset=utf-8');