我已经为重定向创建了这个脚本。它可以正常工作以匹配大小写,但不执行切换案例。代码有问题吗?
<script type="text/javascript">
window.onload = function () {
var elements = document.getElementsByTagName('a');
for (var i = 0; i < elements.length; i++) {
elements[i].href= escape(elements[i].href);
(function(index){
elements[index].onclick = function () {
var string = elements[index].href; //href value
var patt1=/\bwww.google.com/g;
var n=string.match(patt1);
switch (n) {
case "www.google.com":
var red = "http://yahoo.com";
elements[index].target = "_blank";
elements[index].href = red;
break;
default:
elements[index].href = unescape(string);
}
}
})(i);
}
}
</script>
<a href="http://www.google.com/" target="-blank">www.google.com</a></br>