Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

close browser tab using javascript/jquery event

I have a logout button on which if user clicks, browser tab need to be closed. I have tried with the following method:

window.close(); 

but its not working in any of the browsers.

like image 732
dvln Avatar asked Nov 01 '22 06:11

dvln


1 Answers

If you try to close any window with window.close() you will get error message like

"Scripts may not close windows that were not opened by script" (Message Depends on Browser)

so, its mean you must have to open windows by JavaScript first to close by your code, like:

window.open("http://www.google.com/");

now you can easily close this window by window.close().

.

Another advantage using this functionality is you can also close Child Window from

Parent Windows`. like:

var win;
$('#click').click(function() {
    win = window.open("test3.html", "something", "width=550,height=170");
});

function closeit() {
    win.close();
}
like image 133
124 Avatar answered Nov 13 '22 05:11

124