Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

character encoding of a framed document was not declared

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)

like image 829
Philip Avatar asked Nov 21 '12 10:11

Philip


2 Answers

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.

like image 179
Adrian Avatar answered Oct 13 '22 00:10

Adrian


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.

Screenshot of the Network tab in DevTools, displaying the Content-Type header of jQuery

like image 33
dotnetCarpenter Avatar answered Oct 12 '22 23:10

dotnetCarpenter