Created
June 7, 2012 02:17
-
-
Save y-yu/2886113 to your computer and use it in GitHub Desktop.
文字化け
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var $ = function ( selector, context ) { | |
context = context || document; | |
return context.querySelector(selector); | |
}; | |
var enc = { | |
s : "Shift_JIS", | |
e : "EUC-JP", | |
u : "UTF-8", | |
i : "ISO-2022-JP" | |
}[location.hash.substr(1)]; | |
var request = new XMLHttpRequest(); | |
request.open("GET", location.href); | |
request.setRequestHeader("content-type", "text/html; charset=" + enc); | |
request.onreadystatechange = function () { | |
if (request.readyState === 4 && request.status === 200) { | |
var newSite = document.createElement("html"); | |
newSite.innerHTML = request.response; | |
var meta = document.createElement("meta"); | |
meta.setAttribute("http-equiv", "Content-Type"); | |
meta.setAttribute("content", "text/html; charset=" + enc); | |
$("html head", newSite).appendChild(meta); | |
$("html").removeChild( $("html head")); | |
$("html").insertBefore($("html head", newSite), document.body); | |
$("html").removeChild( $("html body")); | |
$("html").appendChild( $("html body", newSite) ); | |
} | |
}; | |
request.send(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment