如何用JS来屏蔽外部链接
例如我的网站A.COM 页面里面有b.com的链接
用JS吧该链接改成a.c0m/goto.php?url=http://b.c0m我找了一段,但是不行求哥哥们帮忙解决:
<script type="text/javascript">
function parseurl($url, $text) {
        if(!$url && preg_match("/((https?|ftp|gopher|news|telnet|rtsp|mms|callto|bctp|ed2k|thunder|synacast){1}:\/\/|www\.)[^\[\"']+/i", trim($text), $matches)) {
                $url = $matches[0];
                $length = 65;
                if(strlen($url) > $length) {
                        $text = substr($url, 0, intval($length * 0.5)).' ... '.substr($url, - intval($length * 0.3));
                }
                if($url == str_replace("a.com","",strtolower($url))){        //检测为外部站点
                        if(substr(strtolower($url), 0, 7) == 'http://') {
                                $url = 'http://a.com/url.php?url='.base64_encode($url);
                        }elseif(substr(strtolower($url), 0, 4) == 'www.') {
                                $url = 'http://a.com/url.php?url='.base64_encode('http://'.$url);
                        }
                } else {        //否则就为自身站点
                        if(substr(strtolower($url), 0, 4) == 'www.') {
                                $url = 'http://'.$url;
                        }
                }
                return '<a href="'.$url.'" target="_blank">'.$text.'</a>';
        } else {
                $url = substr($url, 1);
                if($url == str_replace("a.com","",strtolower($url))){        //检测为外部站点
                        if(substr(strtolower($url), 0, 7) == 'http://') {
                                $url = 'http://a.com/url.php?url='.base64_encode($url);
                        }elseif(substr(strtolower($url), 0, 4) == 'www.') {
                                $url = 'http://a.com/url.php?url='.base64_encode('http://'.$url);
                        }
                } else {        //否则就为自身站点
                        if(substr(strtolower($url), 0, 4) == 'www.') {
                                $url = 'http://'.$url;
                        }
                }
                return '<a href="'.$url.'" target="_blank">'.$text.'</a>';
        }
}
</script>