本人遇到一个难题,跪求答案,请各位高手们帮忙,问题如下:点击 http://www.qq.com/index.htm上的一个连接(连接打开网站www.baidu.com)现在的问题是:
1.点击连接打开 www.baidu.com 的同时,怎么让 www.qq.com/index.htm这个页面也转向新的网址www.sina.com注:http://www.qq.com/index.htm 上的连接是固定指向www.baidu.com这个网址的改不了 (因为在QQ做的广告连接不是咱们要改就能改的)

解决方案 »

  1.   

    插入事件,範例如下。<html>
    <script type="text/javascript" >
    function init(){
    var aElms = document.getElementsByTagName("a");
    for(var i=0;i<aElms.length;i++){
    aElms[i].addEventListener('click',goUrl,false)
    }
    }
    function goUrl(){
     document.location.href='http://www.sina.com';
    }
    </script>
    <body onload="init()">
    <a href="http://www.baidu.com" target="_blank">1111</a><br>
    <a href="http://www.baidu.com" target="_blank">2222</a><br>
    <a href="http://www.baidu.com" target="_blank">3333</a><br>
    <a href="http://www.baidu.com" target="_blank">4444</a><br>
    <a href="http://www.baidu.com" target="_blank">5555</a><br>
    <a href="http://www.baidu.com" target="_blank">6666</a><br>
    <a href="http://www.baidu.com" target="_blank">7777</a><br>
    <a href="http://www.baidu.com" target="_blank">8888</a><br>
    <a href="http://www.baidu.com" target="_blank">9999</a><br>
    <a href="http://www.baidu.com" target="_blank">0000</a><br>
    </body>
    </html>
      

  2.   

    修正IE和firework都能用。<html>
    <script type="text/javascript" >
    function init(){
    var aElms = document.getElementsByTagName("a");
    for(var i=0;i<aElms.length;i++){
    try{
    aElms[i].addEventListener('click',goUrl,false)
    }catch(e){
    aElms[i].attachEvent('onclick', goUrl);
    }
    }
    }
    function goUrl(){
     document.location.href='http://www.sina.com';
    }
    </script>
    <body onload="init()">
    <a href="http://www.baidu.com" target="_blank">1111</a><br>
    <a href="http://www.baidu.com" target="_blank">2222</a><br>
    <a href="http://www.baidu.com" target="_blank">3333</a><br>
    <a href="http://www.baidu.com" target="_blank">4444</a><br>
    <a href="http://www.baidu.com" target="_blank">5555</a><br>
    <a href="http://www.baidu.com" target="_blank">6666</a><br>
    <a href="http://www.baidu.com" target="_blank">7777</a><br>
    <a href="http://www.baidu.com" target="_blank">8888</a><br>
    <a href="http://www.baidu.com" target="_blank">9999</a><br>
    <a href="http://www.baidu.com" target="_blank">0000</a><br>
    </body>
    </html>
      

  3.   

    虽然没有解决我的问题,还是非常感谢您的回复,费心了。这个效果还是没有实现(连接不是在我自己的网站上的,而是在其它网站如QQ.COM上的连接):
    注:http://www.qq.com/index.htm 上的连接是固定指向www.baidu.com这个网址的改不了 (因为在QQ做的广告连接不是咱们要改就能改的)