---
title: "How to document.write loses encoding (Chrome)"  
description: "How to document.write loses encoding (Chrome)"  
author: "Anonymous User"  
published: 2015-02-01  
updated: 2015-02-01  
canonical: https://www.mindstick.com/forum/12926/how-to-document-write-loses-encoding-chrome  
category: "javascript"  
tags: ["ajax", "jquery", "html"]  
reading_time: 2 minutes  

---

# How to document.write loses encoding (Chrome)

i've been getting a html page using ajax, then open a new window and writting the html data into this new window.

Its [working fine](https://answers.mindstick.com/qa/95550/why-is-the-safari-browser-not-working-fine) on IE 8... however, Chrome is messing the [encoding](https://www.mindstick.com/interview/752/how-is-encoding-handled-in-ajax)..

**My code:**

```
 $('#bo').submit(function( event ) {              $.ajax({                url : "./home.html",                cache : false,                type: 'POST',                dataType : "html",            }).done(function(data) {                 var doc = window.open("", "_blank");                 doc.document.write(data);                 doc.document.close();                });              event.preventDefault();            return false;        });
```

The data [string contains](https://www.mindstick.com/forum/159365/how-to-check-if-a-string-contains-letters-only-in-sql) this html:

```
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE"></head> <body>    <div id="ui-master">        <div id="ui-header">         </div>   </div></body></html>
```

Can [anyone give me](https://answers.mindstick.com/qa/41194/can-anyone-give-me-some-high-and-low-points-of-each-of-the-four-first-presidential-administrations) a [direction](https://yourviews.mindstick.com/story/5034/10-animals-with-the-best-sense-of-direction) here? Im a bit confused why it works on IE but not on Chrome.. When the dom is ready, im loading some jquery [features](https://www.mindstick.com/articles/12993/5-advanced-features-for-your-odoo-ecommerce-theme), like jquery dialogs, jquery growl [messages](https://www.mindstick.com/news/4166/google-rolling-out-gemini-extensions-for-messages-whatsapp-and-spotify) and [knockout](https://www.mindstick.com/forum/33538/how-to-insert-data-in-database-using-knockout-js) stuff to fill the page, not sure if its relevant.

The strange fact is that if I change the code do something like [replace](https://yourviews.mindstick.com/view/81330/cow-antibody-research-in-usa-a-step-ahead-to-replace-plasma-therapy) my window html instead of opening a new popup.. the encoding will work fine =( Thanks

## Replies

### Reply by Anonymous User

Although I wouldn't recommend to use document.write, and I'm not sure this will solve your problem, you can try forcing the content encoding on the $.ajax function like this:

```
$.ajax({                url : "./home.html",                cache : false,                contentType: "text/html;charset=UTF-8"                type: 'POST',                dataType : "html",            });
```


---

Original Source: https://www.mindstick.com/forum/12926/how-to-document-write-loses-encoding-chrome

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
