views:

284

answers:

1

Is it possible to check if the browser user has opened a new tab, is closing (not minimizing) the current tab/page, or changing the url? Don't worry, nothing suss it's just for a novelty website. Could someone let me know if this is/isn't feasible via javascript (preferably jquery), and if so, what method to look into. Thanks

EDIT: In the end it was easier to check if the mouse went above the window with the following code:

    $(window).bind("mouseout", function(e)
    {
    if (e.pageY < 0)
        {
            alert('you are leaving the page');
        }
    });
+1  A: 

It is somewhat feasible using the unload event.

karim79
The unload event is good for closing the tab or going away. But it won't tell him when a new tab is opened. I don't think he can get that.
Eric Hogue
I think this must be as close as I can get. It seems undoable, so instead I'll check for when the mouse navigates above the document window.
Lobe
I was thinking solely in term of 'event triggered when user tries to leave the page'. Detecting the opening of a new tab might be possible via key capture, but I doubt it's possible to capture via File->New Tab.
karim79
Checking for Ctr + t could do it, however checking for the mouse going above the window is good enough. I added the code in my post
Lobe