Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
>Hi, i'm working in mvc4 web application we are using c#,jquery my task is to close the current tab on a button click i have tried with some jquery code it works well in IE but it does't work for Firefox and Chrome can any one help me how to close current tab using jquery?
JavaScript
    $('#submitCase').click(function () {                                                                                     
                $('#Messagesub').html("You are Closing Window");
                $("#Dialog").dialog({                    
                    modal: true,
                    resizable: false,
                    buttons: {
                        "Ok": function () {
                            CloseWithWindowOpenTrick();                           
                        }
                    }
                });
            });

function CloseWithWindowOpenTrick() {
        var objWindow = window.open(location.href, "_self");
        objWindow.close();
    }
Posted
Updated 21-Mar-15 1:02am
Comments
Joan Magnet 21-Mar-15 13:15pm    
Maybe this can help.

http://stackoverflow.com/questions/2076299/how-to-close-current-tab-in-a-browser-window

jQuery isn't magic or a new technology, it's just a javascript library, it can't do anything javascript can't. The reason closing the window doesn't work in various browsers is because browsers vary in the support they offer these non-standard features. In general browsers are moving away from supporting things that interfere with the user experience. If the user wants to close a tab at the clock of a button they'll click the "X" button on the tab. It is for the user to control their experience, not your code.
 
Share this answer
 
You can try window.top.close(); or window.close();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900