锚点问题!
因为有需要,要把页面中的一些字符提取出来,用于替换。
可以下面的例子中,对于锚点却存在问题,不能链接到锚点上去,如果不执行window.onload里的代码却可以链过去。但window.onload里的代码是正确的,确实确实替换了。。想不通???
把以下文件保存为test.htm:
<TITLE> || <$WebName$> <$WebURLDomain$> </TITLE>
<script>
var o_navigator = navigator.userAgent;
var isIE = (o_navigator.indexOf( "MSIE ") > -1) ? true : false;
var req;
var CharDefineValue = " ";
var re=/[\W]/g;
var myJSONDefine = [
{
OptionType: "CharacterDefine ",
OptionCode: "WebName ",
MasterValue: "无线网站 ",
SlaveValue: " ",
OtherValue: " ",
Remark: "定义网站名称 "
},
{
OptionType: "CharacterDefine ",
OptionCode: "WebURL ",
MasterValue: "http://www ",
SlaveValue: " ",
OtherValue: " ",
Remark: "定义网站地址 "
},
{
OptionType: "CharacterDefine ",
OptionCode: "City ",
MasterValue: "重庆市 ",
SlaveValue: " ",
OtherValue: " ",
Remark: "定义城市 "
},
{
OptionType: "CharacterDefine ",
OptionCode: "Email ",
MasterValue: " ",
SlaveValue: " ",
OtherValue: " ",
Remark: "定义邮箱地址 "
},
]
function GetCharDefineValue(url,str){
var returnValue = " "
for(var i=0;i <myJSONDefine.length;i++){
if(str==myJSONDefine[i].OptionCode && myJSONDefine[i].OptionType== "CharacterDefine " )
{returnValue = myJSONDefine[i].MasterValue;return returnValue;}
}
return returnValue;
}
var tt= " "
window.onload = function(){
document.title = document.title.replace(/ <\$WebName\$> /g,GetCharDefineValue( " ", "WebName "));
document.title = document.title.replace(/ <\$WebURL\$> /g,GetCharDefineValue( " ", "WebURL "));
var TagA = document.getElementsByTagName( "a ");
for(i = 0; i < TagA.length; i++){
if(isIE){
if(TagA[i].href!= " ") TagA[i].href = TagA[i].href.replace(/ <\$WebName\$> /g,GetCharDefineValue( " ", "WebName "));
if(TagA[i].href!= " ") TagA[i].href = TagA[i].href.replace(/ <\$WebURL\$> /g,GetCharDefineValue( " ", "WebURL "));
}
else{
//在FireFox中连接已经编码了 %3C %3E
if(TagA[i].href!= " ") TagA[i].href = TagA[i].href.replace(/%3C\$WebName\$%3E/g,GetCharDefineValue( " ", "WebName "));
if(TagA[i].href!= " ") TagA[i].href = TagA[i].href.replace(/%3C\$WebURL\$%3E/g,GetCharDefineValue( " ", "WebURL "));
}
tt += TagA[i].name+ " <--> ";
if(TagA[i].name!= " ") TagA[i].name = TagA[i].name.replace(/ <\$WebName\$> /g,GetCharDefineValue( " ", "WebName "));
if(TagA[i].name!= " ") TagA[i].name = TagA[i].name.repl