How to close a window using jQuery

前端 未结 5 1577
隐瞒了意图╮
隐瞒了意图╮ 2020-12-15 03:29

How to close a window using jQuery for all browser compatibility?



        
相关标签:
5条回答
  • 2020-12-15 04:13
    $(element).click(function(){
        window.close();
    });
    

    Note: you can not close any window that you didn't opened with window.open. Directly invoking window.close() will ask user with a dialogue box.

    0 讨论(0)
  • 2020-12-15 04:17

    For IE: window.close(); and self.close(); should work fine.

    If you want just open the IE browser and type

    javascript:self.close() and hit enter, it should ask you for a prompt.

    Note: this method doesn't work for Chrome or Firefox.

    0 讨论(0)
  • 2020-12-15 04:29

    This will only work for windows which are opened by using window.open(); method. Try this

    var tmp=window.open(params);
    tmp.close();
    
    0 讨论(0)
  • 2020-12-15 04:30

    You can only use the window.close function when you have opened the window using window.open(), so I use the following function:

    function close_window(url){
        var newWindow = window.open('', '_self', ''); //open the current window
        window.close(url);
     }
    
    0 讨论(0)
  • 2020-12-15 04:33

    just window.close() is OK, why should write in jQuery?

    0 讨论(0)
提交回复
热议问题