想用javacript打开本地网页,但路径中有中文就不行了,如何解决?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Untitled Page</title>
<script language="javascript" type="text/javascript">
// <!CDATA[
function qswhEncodeURI(str)
{
var m="",sp="!'()*-.0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz~"
for(var i=0;i<str.length;i++)
{
if(sp.indexOf(str.charAt(i))!=-1)
{
m+=str.charAt(i)
}else
{
var n=str.charCodeAt(i)
var t="0"+n.toString(8)
if(n>0x7ff)
m+=("%"+(224+parseInt(t.slice(-6,-4),8)).toString(16)+"%"+(128+parseInt(t.slice(-4,-2),8)).toString(16)+"%"+(128+parseInt(t.slice(-2),8)).toString(16)).toUpperCase()
else if(n>0x7f)
m+=("%"+(192+parseInt(t.slice(-4,-2),8)).toString(16)+"%"+(128+parseInt(t.slice(-2),8)).toString(16)).toUpperCase()
else if(n>0x3f)
m+=("%"+(64+parseInt(t.slice(-2),8)).toString(16)).toUpperCase()
else if(n>0xf)
m+=("%"+n.toString(16)).toUpperCase()
else
m+=("%"+"0"+n.toString(16)).toUpperCase()
}
}
return m;
}
function Button1_onclick() {
var loc="file:/" + qswhEncodeURI(document.getElementById("File1").value);
var code='location="'+loc+'"';
eval(code);
}
// ]]>
</script>
</head>
<body>
please choose the file you want to open<br />
<input id="File1" type="file" />
<input id="Button1" type="button" value="button" onclick="return Button1_onclick()" />
</body>
</html>
感觉问题出在escape转换上,反正只要路径中包含中文就打不开,我用javascript的escape函数转换也不行,如何做才能用上述代码打开包含中文路径的文件?