初见:http://topic.csdn.net/u/20100125/15/3fbabc13-5937-4dce-86ee-93aba08d3d6e.html?67085
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
        <title>弹窗代码</title>
        <style type="text/css">
            td {font-size: 12px;}
        </style>
  <SCRIPT LANGUAGE="JavaScript" >
    function addEventSimple(obj,evt,fn) {
        if (obj.addEventListener)
            obj.addEventListener(evt,fn,false);
        else if (obj.attachEvent)
            obj.attachEvent('on'+evt,fn);
    }
    
    function removeEventSimple(obj,evt,fn) {
        if (obj.removeEventListener)
            obj.removeEventListener(evt,fn,false);
        else if (obj.detachEvent)
            obj.detachEvent('on'+evt,fn);
    }
function fuyouPopUp(targetUrl){
      var w=screen.availWidth;
      var h=screen.availHeight;
      var casalef='width='+w+',height='+h+',toolbar=1,location=1,titlebar=1,menubar=1,scrollbars=1,resizable=1,directories=1,status=1';
      var l = 0 ;
      var t = 0 ;
      var i=window.open("about:blank","_backad",casalef+",left="+l+",top="+t);
         i.blur(); 
        i.opener.focus(); 
        i.location=targetUrl;
}
function fuyouClickPopup(targetURl){
    window.documentClick = function (){//documentClick是自定的属性吧
        fuyouPopUp(targetURl);
    }
    addEventSimple(document,'click', documentClick);//这时应该是不是window.documentClick,而不是documentClick
}
function fuyouWinOpen(url){
    try{
        fuyouPopUp(url);
    }catch(e){
        fuyouClickPopup(url)
    }finally{
        removeEventSimple(document, 'click', window.documentClick);//前面注册事件,这事又取消注册事件函数!
//fuyouClickPopup函数仅仅是注册document.onclick事件函数,但这里马上又取消了document.onclick ,难道这样可以吗
//不等执行完了,才取消吗
    }
}function fuyouPop (url){
          fuyouWinOpen(url);
    }
       fuyouPop ('http://www.sina.com');
        </SCRIPT>
      
   
       
    </head>
<body>
 cpm
<a href="http://www.baidu.com">baidu</a>
</body></html>有些疑问我写在源代码里了好最主要是点击不会弹出来 我在firebug里调试了见报错

解决方案 »

  1.   

    初始时,执行一次fuyouWinOpen后,会接着remove掉document的click事件。你再点击当然不会弹出了。
    把fuyouPop ('http://www.sina.com'); 换成fuyouClickPopup('http://www.sina.com');
    每次点击document就会弹出来了
      

  2.   

    哦,明白了! 但这里还有点疑问:
     window.documentClick = function (){//documentClick是自定的属性吧
            fuyouPopUp(targetURl);
        }
        addEventSimple(document,'click', documentClick);//这时应该是不是documentClick,
                                                              //而不是window.documentClick
                                                     //因为documentClick是自定义的
                                                            //window属 性,为什么可以直接这用
                                                            //难道找不到没定义的变量时,
                                                            //会自动在window对象里找吗?
    }
      

  3.   

    全局的变量其实就是window的属性,全局的函数其实就是window的方法。window的属性和方法可以忽略window,比如alert,其实是window.alert.
    alert(window.documentClick  === documentClick );
      

  4.   


    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
            <title>弹窗代码</title>
            <style type="text/css">
                td {font-size: 12px;}
            </style>
      <SCRIPT LANGUAGE="JavaScript" >
        function addEventSimple(obj,evt,fn) {
            if (obj.addEventListener)
                obj.addEventListener(evt,fn,false);
            else if (obj.attachEvent)
                obj.attachEvent('on'+evt,fn);
        }
        
        function removeEventSimple(obj,evt,fn) {
            if (obj.removeEventListener)
                obj.removeEventListener(evt,fn,false);
            else if (obj.detachEvent)
                obj.detachEvent('on'+evt,fn);
        }
    function fuyouPopUp(targetUrl){
          var w=screen.availWidth;
          var h=screen.availHeight;
          var casalef='width='+w+',height='+h+',toolbar=1,location=1,titlebar=1,menubar=1,scrollbars=1,resizable=1,directories=1,status=1';
          var l = 0 ;
          var t = 0 ;
          var i=window.open("about:blank","_backad",casalef+",left="+l+",top="+t);
             i.blur(); 
            i.opener.focus(); 
            i.location=targetUrl;
    }
    function fuyouClickPopup(targetURl){
        window.documentClick = function (){//documentClick是自定的属性吧
            fuyouPopUp(targetURl);
        }
        addEventSimple(document,'click', documentClick);//这时应该是不是window.documentClick,而不是documentClick
    }
    function fuyouWinOpen(url){
        try{
            fuyouPopUp(url);
        }catch(e){
            fuyouClickPopup(url)
        }finally{
            removeEventSimple(document, 'click', window.documentClick);

        }
    }function fuyouPop (url){
              fuyouWinOpen(url);
        }
        fuyouClickPopup('http://www.sina.com'); 
            </SCRIPT>
          
       
           
        </head>
    <body>
     cpm
    <a href="http://www.baidu.com">baidu</a>
    </body></html>最后完整的代码如上:
    但还有过一个问题:就是点一击了下,再点击还是会出弹出窗口,我刚仔细测试!