title: How to change the character encoding in UIWebView?
body: <p><em>Summary of the problem:</em> When browsing non-English sites that does not explicitly specify the correct character encoding with UIWebView on the iOS, the page cannot be displayed correctly.  </p>
  
  <p><em>Detailed explanation:</em> As the <code>loadRequest:</code> method in UIWebView will use the encoding specified in the charset header sent from the web server or the charset written in the HTML meta tag, and default to iso-8859-1 (well, I am not too sure about this) when charset is not specified, which cause non-English sites cannot display properly.  </p>
  
  <p>I have tried to Google for a way to change the charset that the UIWebView use, but the only way is to use the <code>loadData:MIMEType:textEncodingName:baseURL:</code> method to specify the encoding name.</p>
  
  <p>However, it is not a good idea to use <code>loadData:MIMEType:textEncodingName:baseURL:</code> + NSURLConnection instead of <code>loadRequest:</code>, because UIWebView won't call the delegate method <code>webView:shouldStartLoadWithRequest:navigationType:</code> for frames, and even if we found a way to get notified when UIWebView load a frame, we cannot call <code>loadData:MIMEType:textEncodingName:baseURL:</code> to load the frame content, because it will load the frame as the outer page if we do that.  </p>
  
  <p>Besides, I have tried to use a javascript hack, but seems that property is read-only and cannot be changed.  </p>
  
  <pre><code>[webView stringByEvaluatingJavaScriptFromString:@"document.characterSet='utf-8';"];  
  </code></pre>
  
  <p>Another workaround is inserting a meta tag to the HTML, and ask UIWebView to load the modified code, but the frame problem mentioned above also apply here.</p>
  
  <pre><code>&lt;meta http-equiv="Content-Type" content="text/html;charset=utf-8"&gt;
  </code></pre>
  
  <p><em>Question:</em> Is there any better solution that can change the character encoding in a loaded webpage in UIWebView, and handle frames properly?</p>