js调用cookies中文乱码
html里的txt调用
<SCRIPT LANGUAGE="JavaScript">
<!--
outputContent('/1/1/1.txt');
//-->
</SCRIPT>
js代码
var domainName = "127.0.0.2";
function $(v){
return document.getElementById(v);
}
function $n(n, index){
var es = document.getElementsByName(n);
if (typeof(index) == 'undefined') {
index = 0;
}
if (index >= es.length) {
index = es.length - 1;
}
return es[index];
}
function Ajax(url, params, callback, method) {
this.createHttpRequest = function() {
if (window.ActiveXObject) {
try {
return new ActiveXObject('Msxml2.XMLHTTP');
} catch (e) {
return new ActiveXObject("Microsoft.XMLHTTP");
}
} else {
return new XMLHttpRequest();
}
}
this.url = url;
this.params = params;
this.callback = callback;
this.method = method == null? "post" : method;
this.xmlHttp = this.createHttpRequest();
window.myAjax = this;
this.doRequest = function() {
var query = "";
for (var param in this.params) {
if (query != "") {
query += "&";
}
query += param + "=" + this.params[param];
}
if (this.method == "post") {
this.xmlHttp.open(this.method, this.url, true);
this.xmlHttp.onreadystatechange = this.stateChanged;
this.xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
this.xmlHttp.send(query);
} else {
if (query.length>0) this.url += "?" + query;
try {
this.xmlHttp.open(this.method, this.url);
} catch (err) {}
this.xmlHttp.onreadystatechange = this.stateChanged;
this.xmlHttp.send(null);
//return this.xmlHttp.responseBody;
}
};
this.stateChanged = function() {
if (myAjax.xmlHttp.readyState==4 || myAjax.xmlHttp.readyState=="complete") {
var data = myAjax.xmlHttp.responseText;
myAjax.callback(data);
}
};
}
function outputContent(uri){
$("text_area").innerHTML = "<font style='color:blue;font-size:24px'>正在加载章节内容,请稍后...</font>";
var fullurl = "";
var defaulturl = "/egbk"+uri;
//if (document.charset.indexOf('big5')==0 || document.charset.indexOf('BIG5')==0){
// fullurl = "/txtbig5"+uri;
//}
//else
fullurl = defaulturl;
var ajax =new Ajax(fullurl, null, showContent, "get");
ajax.doRequest();
}
function showContent(message) {
if (message.length >0) {
message = message.replace(/ /g, " ")
message = message.replace(/\n/g, "<br />");
}
$("text_area").innerHTML = message;
//alert(message);
}
function showInfoTip(message) {
if (message.length >0) alert(message.replace(/<br \/>/g, "\n"));
}
function setCookie(name,value,days) {
if(days) {
var exp = new Date();
exp.setTime(exp.getTime() + days*24*60*60*1000);
document.cookie = name + "="+ escape(value) +";expires="+ exp.toGMTString()+";path=/;domain=" + domainName;
} else {
document.cookie = name + "="+ escape(value)+";path=/;domain=" + domainName;
}
}
function setCookieWithHour(name,value,hours) {
if(hours) {
var exp = new Date();
exp.setTime(exp.getTime() + hours*60*60*1000);
document.cookie = name + "="+ escape(value) +";expires="+ exp.toGMTString()+";path=/;domain=" + domainName;
} else {
document.cookie = name + "="+ escape(value)+";path=/;domain=" + domainName;
}
}
function getCookie(name) {
var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
if(arr != null) return unescape(arr[2]); return null;
}
function getCookieForInt(name) {
var value = getCookie(name);
if (value == "" || value == null) {
return 0;
} else {
return parseInt(value);
}
}
function setBackground(color) {
setCookie("color", color, 30);
document.bgColor = "#" + color;
}
function setFontSize(fontSize) {
setCookie("fontSize", fontSize, 30);
var textArea = $("text_area");
if (textArea != null) textArea.style.fontSize= fontSize + "px";
}
//单章下载
var visitedChapterCount = getCookieForInt("_vcc");
visitedChapterCount++;
setCookieWithHour("_vcc", visitedChapterCount, 1);
function LoadSet() {
var _color=getCookie("color");
if (_color == null || _color == "undefined") _color="E7F4FE";
var _fontsize=getCookie("fontSize");
if (_fontsize == null || _fontsize == "undefined") _fontsize="14";
setBackground(_color);setFontSize(_fontsize);
}
function showChapterTitleTopAd() {
LoadSet();
}
function showChapterTitleBottomAd() {
document.writeln("<script type=\"text/javascript\">BAIDU_CLB_singleFillSlot(\"64909\");</script>");
}
function showListTitleTopAd(w) {
if (w == '01')
{
showChapterPagerTopAd();
}
if (w == '02')
{
document.writeln("<script type=\"text/javascript\">BAIDU_CLB_singleFillSlot(\"64912\");</script>");
}
LoadSet();
}
function showListTitleBottomAd() {
swapInnerHtml("tbad","topad01_ad");
}
function showChapterPagerTopAd() {
document.writeln("<script type=\"text/javascript\">BAIDU_CLB_singleFillSlot(\"64911\");</script>");
}
function showChapterPagerBottomAd() {
if (visitedChapterCount > 2) {
document.getElementById("chapter_pager").style.paddingBottom="0px";
document.getElementById("pbtad").style.marginTop="-3px";
}
swapInnerHtml("tbad","tbad_ad");
swapInnerHtml("pbtad","ptopad_ad");
}
function showChapterBottomAd() {
}
function showChapterBottomAd2() {
}
function showChapterBottomAd3() {
}
// chapters
function showChaptersTopAd() {
}
function showChaptersBottomAd() {
}
// novel
function showNovelTopAd() {
}
function swapInnerHtml(name, name4) {
var ad_ad=document.getElementById(name4);
var ad_ad_content = ad_ad.innerHTML;
document.getElementById(name).innerHTML = ad_ad.innerHTML;
ad_ad.innerHTML="";
}
function writeAdJs() {
document.body.oncopy = function () {
setTimeout( function () {
var text = clipboardData.getData("text");
if (text && text.length > 100) {
var novelIndex = location.href;
var lastPos = novelIndex.lastIndexOf("/");
if (lastPos > -1) {
novelIndex = novelIndex.substring(0, lastPos + 1);
} else {
}
text = text + "\r\n 您所阅读的文章来自互联网:"+novelIndex;
clipboardData.setData("text", text);
}
}, 100 );
};
}
var speed = 5;
var currentpos=1;
var timer;
function stopScroll()
{
clearInterval(timer);
}
function beginScroll()
{
timer=setInterval("scrolling()",300/speed);
}
//for xhtml
function scrolling()
{
currentpos=document.documentElement.scrollTop;
window.scroll(0,++currentpos);
if(currentpos!=document.documentElement.scrollTop) clearInterval(timer);
}
document.onmousedown=stopScroll;
document.ondblclick=beginScroll;