我的代码如下
<div class="clear">
    </div>
       <input type="button" class="closebtn" value=""  onclick="window.close()" />
   </div>
这个太简单了,感觉很龌龊。在网上也搜不到什么好的。要类似中华英才活51job上的那种,点击直接关掉窗口的!
谢谢,受用的话以分鼓励~

解决方案 »

  1.   


    添加 
    <OBJECT id="WebBrowser" classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" height="0" width="0"> </OBJECT> 
    调用WebBrowser.ExecWB(45,1)来关闭窗口 
      

  2.   

    你说的是哪个关闭? 51JOB上那个不是窗口 是DIV
      

  3.   

    我这里也是div啊,能关闭就行啊
      

  4.   

    这个效果?<script type="text/javascript">
    var docEle = function()
    {
        return document.getElementById(arguments[0]) || false;
    }function openNewDiv(_id)
    {
        var m = "mask";
        if (docEle(_id)) document.body.removeChild(docEle(_id));
        if (docEle(m)) document.body.removeChild(docEle(m));    //mask遮罩层    var newMask = document.createElement("div");
        newMask.id = m;
        newMask.style.position = "absolute";
        newMask.style.zIndex = "1";
        _scrollWidth = Math.max(document.body.scrollWidth,document.documentElement.scrollWidth);
        _scrollHeight = Math.max(document.body.scrollHeight,document.documentElement.scrollHeight);
        newMask.style.width = _scrollWidth + "px";
        newMask.style.height = _scrollHeight + "px";
        newMask.style.top = "0px";
        newMask.style.left = "0px";
        newMask.style.background = "#33393C";
        newMask.style.filter = "alpha(opacity=40)";
        newMask.style.opacity = "0.40";
        document.body.appendChild(newMask);    //新弹出层    var newDiv = document.createElement("div");
        newDiv.id = _id;
        newDiv.style.position = "absolute";
        newDiv.style.zIndex = "9999";
        newDivWidth = 400;
        newDivHeight = 200;
        newDiv.style.width = newDivWidth + "px";
        newDiv.style.height = newDivHeight + "px";
        newDiv.style.top = (document.body.scrollTop + document.body.clientHeight/2 - newDivHeight/2) + "px";
        newDiv.style.left = (document.body.scrollLeft + document.body.clientWidth/2 - newDivWidth/2) + "px";
        newDiv.style.background = "#EFEFEF";
        newDiv.style.border = "1px solid #860001";
        newDiv.style.padding = "5px";
        newDiv.innerHTML = " ";
        document.body.appendChild(newDiv);    //弹出层滚动居中    function newDivCenter()
        {
            newDiv.style.top = (document.body.scrollTop + document.body.clientHeight/2 - newDivHeight/2) + "px";
            newDiv.style.left = (document.body.scrollLeft + document.body.clientWidth/2 - newDivWidth/2) + "px";
        }
        if(document.all)
        {
            window.attachEvent("onscroll",newDivCenter);
        }
        else
        {
            window.addEventListener('scroll',newDivCenter,false);
        }    //关闭新图层和mask遮罩层
     var newA = document.createElement("div");
        newA.innerText ="关闭";
        newA.onclick = function(){
            if(document.all)
            {
                window.detachEvent("onscroll",newDivCenter);
            }
            else
            {
                window.removeEventListener('scroll',newDivCenter,false);
            }
            document.body.removeChild(docEle(_id));
            document.body.removeChild(docEle(m));
            return false;
        }
        newDiv.appendChild(newA);}
    </script>
    <body><a onclick="openNewDiv('newDiv');return false;" style="cursor:pointer">弹出层</a>
    </body>
      

  5.   

    LZ什么浏览器?
     newA.innerText ="关闭";
    换成 newA.innerHTML="关闭";
      

  6.   

    我用的IE呀?BEENZ兄弟,你用什么浏览器呀?
      

  7.   

    IE啊,IE6 7都可以..FF和chrome都可以,唯一没测试IE8
      

  8.   


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
     <head>
      <title> LightBox </title>
      <style type="text/css">
      #box {
        text-align:right;
        background-color: #fff;
        border: 20px solid #000000;
      }
      </style>
     </head>
     <body>
     <script type="text/javascript">
     <!--
        var $ = function(id){
            return 'string' == typeof id ? document.getElementById(id) : id;
        }    var $d = (document.compatMode == 'CSS1Compat') ? document.documentElement : document.body;    var isIE = navigator.userAgent.indexOf('MSIE') != -1;
        var isIE6 = navigator.userAgent.indexOf('MSIE 6.0') != -1;
        isIE6 && document.execCommand('BackgroundImageCache', false, true);    var Extend = function(destination, source){
            for(var pro in source){
                destination[pro] = source[pro];
            }
            return destination;
        }    function addEvent(oTarget, sType, fnHandler){
            if(window.attachEvent){
                oTarget.attachEvent("on"+sType, fnHandler);
            }else if(window.addEventListener){
                oTarget.addEventListener(sType, fnHandler, false);
            }else{
                oTarget["on"+sType] = fnHandler;
            }
        }    function removeEvent(oTarget, sType, fnHandler){
            if(window.detachEvent){
                oTarget.detachEvent("on"+sType, fnHandler);
            }else if(window.removeEventListener){
                oTarget.removeEventListener(sType, fnHandler, false);
            }else{
                oTarget["on"+sType] = null;
            }
        }    function setOpacity(obj, o){
            if(!obj.currentStyle || !obj.currentStyle.hasLayout) obj.style.zoom = 1;
            if(!!isIE)obj.style.filter = 'alpha(opacity=' + Math.round(o) + ')';
            else obj.style.opacity = o / 100;
        }    var Bind = function(object, fun){
            return function(){
                fun.apply(object, arguments);
            }
        }    var Class = {
            create: function(){
                return function(){
                    this.initialize.apply(this, arguments);
                }
            }
        }    var OverLay = Class.create();
        OverLay.prototype = {
            initialize: function(options){
                this.SetOptions(options);
                Extend(this, this.options);
                this.Lay = document.body.insertBefore(document.createElement('div'), document.body.childNodes[0]);
                with(this.Lay.style){
                    position = 'fixed';left = top = '0px';width = height = '100%';zIndex = parseInt(this.zIndex);
                    backgroundColor = this.bgColor;display = 'none';
                }
                if(isIE6){
                    this.Lay.style.position = 'absolute';
                    this._resize = Bind(this, function(){
                        this.Lay.style.width = Math.max($d.clientWidth, $d.scrollWidth) + "px";
                        this.Lay.style.height = Math.max($d.clientHeight, $d.scrollHeight) + "px";
                    });
                    this.Lay.innerHTML += "<iframe style='position:absolute;left:0px;top:0px;widht:100%;height:100%;filter:alpha(opacity=0);z-index:-1'></iframe>";
                }
            },        Show: function(){
                if(isIE6){this._resize();addEvent(window,'resize',Bind(this, this._resize))};
                setOpacity(this.Lay, this.opacity);
                this.Lay.style.display = "block";                    
            },        SetOptions: function(options){
                this.options = {
                    bgColor: "#000000",
                    opacity: 80,
                    zIndex: 1000
                };
                Extend(this.options, options || {});
            },        Close: function(){            
                this.Lay.style.display = "none";
                isIE6 && removeEvent(window,'resize',Bind(this,this._resize));
            }
        }    var LightBox = Class.create();
        LightBox.prototype = {
            initialize: function(boxId, options){
                this.Box = $(boxId);
                this.Lay = new OverLay();
                this.SetOptions(options);
                Extend(this, this.options);            this.Box.style.display = "none";
                this.Box.style.zIndex = parseInt(this.Lay.zIndex) + 1;
                if(isIE6){
                    this._top = this._left = 0; 
                    this._fixed = Bind(this, function(){ this.isCenter ? this.SetCenter() : this.FixScroll(); });
                }
            },        SetCenter: function(){
                this.Box.style.marginLeft = $d.scrollLeft - this.Box.offsetWidth / 2 + "px";
                this.Box.style.marginTop = $d.scrollTop  - this.Box.offsetHeight / 2 + "px";
            },        FixScroll: function(){
                this.Box.style.top = $d.scrollTop - this._top + this.Box.offsetTop + "px";
                this.Box.style.left = $d.scrollLeft - this._left + this.Box.offsetLeft + "px";
                this._top = $d.scrollTop; this._left = $d.scrollLeft;
            },        Show: function(){
                this.hasLayer && this.Lay.Show();
                this.Box.style.position = this.isScroll && !isIE6 ? 'fixed' : 'absolute';    
                this.Box.style.display = "block";
                if(this.isCenter){
                    this.Box.style.left = "50%"; this.Box.style.top = "50%";
                    if(this.isScroll){
                        this.Box.style.marginLeft = -this.Box.offsetWidth / 2 + "px";
                        this.Box.style.marginTop =  - this.Box.offsetHeight / 2 + "px";
                    }else {
                        this.SetCenter();
                    }
                }else{
                    this.Box.style.left = "20%"; this.Box.style.top = "10%";
                }
                if(isIE6){
                    this.isCenter ? this.SetCenter() : this.isScroll && this.FixScroll();
                    this.isScroll && addEvent(window,'scroll',this._fixed);        
                }        },        SetOptions: function(options){
                this.options = {
                    hasLayer: true,
                    isCenter: true,
                    isScroll: true
                };
                Extend(this.options, options || {});
            },        Close: function(){
                this.Box.style.display = "none";
                this.Lay.Close();
            }
        }
     //-->
     </script>
      <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
     <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
      <div id="openbtn"><img src="http://images.cnblogs.com/cnblogs_com/s_liangchao1s/201609/o_28t.jpg"/></div>
      <div id="box">
        <img src="http://images.cnblogs.com/cnblogs_com/s_liangchao1s/201609/o_28.jpg"/></br>
        <span id="clobtn">
            <img src='http://images.cnblogs.com/cnblogs_com/s_liangchao1s/201609/o_closelabel.gif'/>
        </span>
      </div>
     <select style="width:100px;">
        <option value="" selected="selected">Test IE6</option>
     </select>
     <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
     <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
     <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
     <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
      <script type="text/javascript">
      <!--
        var box = new LightBox('box');
        $('openbtn').onclick = function(){
            box.Show();
        }
        $('clobtn').onclick = function(){
            box.Close();
        }  //-->
      </script>
     </body>
    </html>试下这个
      

  9.   

    我把
    newA.innerText ="关闭"; 
    换成 newA.innerHTML="关闭";
    在IE7下还是关闭不了原来的那个窗口呀~
    你那个弹出层如果一点关闭把之前那个窗口确认关闭就好了~
      

  10.   

    错,是后面的父窗口,而不是div?
      

  11.   

    恩,对啊 关闭后面的父窗口,而不是DIV,你那个弹出层 应该弹出,确认关闭么?或者直接关掉
      

  12.   

    这样么?<script type="text/javascript">
        var docEle = function()
        {
            return document.getElementById(arguments[0]) || false;
        }    function openNewDiv(_id)
        {
            var m = "mask";
            if (docEle(_id)) document.body.removeChild(docEle(_id));
            if (docEle(m)) document.body.removeChild(docEle(m));        //mask遮罩层        var newMask = document.createElement("div");
            newMask.id = m;
            newMask.style.position = "absolute";
            newMask.style.zIndex = "1";
            _scrollWidth = Math.max(document.body.scrollWidth,document.documentElement.scrollWidth);
            _scrollHeight = Math.max(document.body.scrollHeight,document.documentElement.scrollHeight);
            newMask.style.width = _scrollWidth + "px";
            newMask.style.height = _scrollHeight + "px";
            newMask.style.top = "0px";
            newMask.style.left = "0px";
            newMask.style.background = "#33393C";
            newMask.style.filter = "alpha(opacity=40)";
            newMask.style.opacity = "0.40";
            document.body.appendChild(newMask);        //新弹出层        var newDiv = document.createElement("div");
            newDiv.id = _id;
            newDiv.style.position = "absolute";
            newDiv.style.zIndex = "9999";
            newDivWidth = 400;
            newDivHeight = 200;
            newDiv.style.width = newDivWidth + "px";
            newDiv.style.height = newDivHeight + "px";
            newDiv.style.top = (document.body.scrollTop + document.body.clientHeight/2 - newDivHeight/2) + "px";
            newDiv.style.left = (document.body.scrollLeft + document.body.clientWidth/2 - newDivWidth/2) + "px";
            newDiv.style.background = "#EFEFEF";
            newDiv.style.border = "1px solid #860001";
            newDiv.style.padding = "5px";
            newDiv.innerHTML = " ";
            document.body.appendChild(newDiv);        //弹出层滚动居中        function newDivCenter()
            {
                newDiv.style.top = (document.body.scrollTop + document.body.clientHeight/2 - newDivHeight/2) + "px";
                newDiv.style.left = (document.body.scrollLeft + document.body.clientWidth/2 - newDivWidth/2) + "px";
            }
            if(document.all)
            {
                window.attachEvent("onscroll",newDivCenter);
            }
            else
            {
                window.addEventListener('scroll',newDivCenter,false);
            }        //关闭新图层和mask遮罩层
            var newA = document.createElement("div");
            newA.innerHTML ="关闭";
            newA.onclick = function(){
                if(document.all)
                {
                    window.detachEvent("onscroll",newDivCenter);
                    window.close();
                }
                else
                {
                    window.removeEventListener('scroll',newDivCenter,false);
                    window.close();
                }
                document.body.removeChild(docEle(_id));
                document.body.removeChild(docEle(m));
                return false;
            }
        newDiv.appendChild(newA);}
    </script>
    <body>    <a onclick="openNewDiv('newDiv');return false;" style="cursor:pointer">弹出层</a>
    </body>
      

  13.   

    可以<script type="text/javascript">
        var docEle = function()
        {
            return document.getElementById(arguments[0]) || false;
        }    function openNewDiv(_id)
        {
            var m = "mask";
            if (docEle(_id)) document.body.removeChild(docEle(_id));
            if (docEle(m)) document.body.removeChild(docEle(m));        //mask遮罩层        var newMask = document.createElement("div");
            newMask.id = m;
            newMask.style.position = "absolute";
            newMask.style.zIndex = "1";
            _scrollWidth = Math.max(document.body.scrollWidth,document.documentElement.scrollWidth);
            _scrollHeight = Math.max(document.body.scrollHeight,document.documentElement.scrollHeight);
            newMask.style.width = _scrollWidth + "px";
            newMask.style.height = _scrollHeight + "px";
            newMask.style.top = "0px";
            newMask.style.left = "0px";
            newMask.style.background = "#33393C";
            newMask.style.filter = "alpha(opacity=40)";
            newMask.style.opacity = "0.40";
            document.body.appendChild(newMask);        //新弹出层        var newDiv = document.createElement("div");
            newDiv.id = _id;
            newDiv.style.position = "absolute";
            newDiv.style.zIndex = "9999";
            newDivWidth = 400;
            newDivHeight = 200;
            newDiv.style.width = newDivWidth + "px";
            newDiv.style.height = newDivHeight + "px";
            newDiv.style.top = (document.body.scrollTop + document.body.clientHeight/2 - newDivHeight/2) + "px";
            newDiv.style.left = (document.body.scrollLeft + document.body.clientWidth/2 - newDivWidth/2) + "px";
            newDiv.style.background = "#EFEFEF";
            newDiv.style.border = "1px solid #860001";
            newDiv.style.padding = "5px";
            newDiv.innerHTML = " ";
            document.body.appendChild(newDiv);        //弹出层滚动居中        function newDivCenter()
            {
                newDiv.style.top = (document.body.scrollTop + document.body.clientHeight/2 - newDivHeight/2) + "px";
                newDiv.style.left = (document.body.scrollLeft + document.body.clientWidth/2 - newDivWidth/2) + "px";
            }
            if(document.all)
            {
                window.attachEvent("onscroll",newDivCenter);
            }
            else
            {
                window.addEventListener('scroll',newDivCenter,false);
            }        //关闭新图层和mask遮罩层
            var newA = document.createElement("div");
            newA.innerHTML ="关闭";
            var newB = document.createElement("div");
            newB.innerHTML ="返回";
            newA.onclick = function(){
                if(document.all)
                {
                    window.detachEvent("onscroll",newDivCenter);
                    window.close();
                }
                else
                {
                    window.removeEventListener('scroll',newDivCenter,false);
                    window.close();
                }
                document.body.removeChild(docEle(_id));
                document.body.removeChild(docEle(m));
                return false;
            }
            newB.onclick = function(){
                if(document.all)
                {
                    window.detachEvent("onscroll",newDivCenter);
                }
                else
                {
                    window.removeEventListener('scroll',newDivCenter,false);
                }
                document.body.removeChild(docEle(_id));
                document.body.removeChild(docEle(m));
                return false;
            }
            newDiv.appendChild(newA);
            newDiv.appendChild(newB);    }
    </script>
    <body>    <a onclick="openNewDiv('newDiv');return false;" style="cursor:pointer">弹出层</a>
    </body>