http://www.myie2.com/html_chs/home.htm?aaa=bbb
似乎不可以这样写吧?难道htm文件也能处理传过来的变量?
http://www.myie2.com/html_chs/home.ASP?aaa=bbb还差不多
不过为空应该都是一些对象为空
似乎不可以这样写吧?难道htm文件也能处理传过来的变量?
http://www.myie2.com/html_chs/home.ASP?aaa=bbb还差不多
不过为空应该都是一些对象为空
比如输入:
http://expert.csdn.net/Expert/topic/2050/2050927.xml?temp=.1739923
alert之后输出就是:
http://expert.csdn.net/Expert/topic/2050/2050927.xml?temp=.1739923
第8行中:
<script src="../standard.js"></script>第336行:
<script language="javascript">
<!--
checkURL();
-->
</script>调用standard.js中的checkURL函数。
standard.js中
//Check URL - a url can be "page.htm?number@archor_name" - By SiC/CYAN
function checkURL() {
var str=new String(window.location);
var n=str.indexOf("?")==-1 ? "" : str.substring(str.indexOf("?")+1,str.length);
var url=str.indexOf("?")==-1 ? str : str.substring(0,str.indexOf("?"));
var nx=n.split("@");
tb_content.height=screen.availHeight-tb_header.clientHeight-64;
if(nx[0]!=""){
switchCell(nx[0],nx[1]);
}else{
switchCell(1);
}
}这里分析了有没有通过url传送过来的参数,有的话就把两个用"@"分割的参数传到switchCell函数中
//Change Cell Content - By SiC/CYAN
function switchCell(n, hash) {
if(navcell.length==undefined||tb.length==undefined){
return;
}
for(i=0;i<navcell.length;i++){
navcell[i].className="tab-off";
tb[i].style.display="none";
}
navcell[n-1].className="tab-on";
tb[n-1].style.display="block";
if(hash){
document.location="#"+hash;
}else{
window.scroll(0,0);
}
}这里引用到的navcell是页面中的若干个单元格的集合,所以navcell[n-1]用来引用其中一个单元格,下标应该是非负整数。但是现在我们传递过来的参数用@分割后的第一个就是aaa=bbb,这也就是现在n的值,所以我们获得的下标应该是:"aaa=bbb"-1=NaN,navcell集合的第NaN个元素应该是……当然是出错啦。
在standard.js文件中有这么一个处理url字符串的函数:
//Check URL - a url can be "page.htm?number@archor_name" - By SiC/CYAN
function checkURL() {
var str=new String(window.location);
var n=str.indexOf("?")==-1 ? "" : str.substring(str.indexOf("?")+1,str.length);
var url=str.indexOf("?")==-1 ? str : str.substring(0,str.indexOf("?"));
var nx=n.split("@");
tb_content.height=screen.availHeight-tb_header.clientHeight-64;
if(nx[0]!=""){
switchCell(nx[0],nx[1]);
}else{
switchCell(1);
}
}
第二句的意思是如果有输入问号,则取得问号之后的字符串,第三句则是取得问号之前的字符串;
整个函数的作用是根据url中的参数来定位,例如当输入:
http://www.myie2.com/html_chs/home.htm?2@archor#archorarchor
时,会定位到“最近更新”(@之后的字符串随便),
输入http://www.myie2.com/html_chs/home.htm?3@archor#archorarchor
则会定位到“商务”