views:

62

answers:

1

To make this simple. I have some text that when you click on it. It then redirects you to home.html.

As follows:

$('#ElementID').click(function () {
        $('#ElementID').html('Redirecting...');
        parent.location = 'http://' + host + '/home.html';
        window.location = 'http://' + host + '/home.html';
});

The actual link is as follows:

<a href="home.html" id="ElementID">Redirect!</a>

Example:

Redirect!

If you right click on the above
You see that you get "Open link in new tab" / "Open link in new window" now can I catch this even and trigger the redirect(On the current window) when they use one of these options not just a straight click.

Now notice that the Jquery.click() also catches just clicking on the element. Can I use something similar to catch "Open link in new tab" / "Open link in new window"

+1  A: 

You can add a blur() handler so that when the user leaves the page (either by clicking another tab, or in anyway loses focus on the logout button after clicking it), it will redirect:

$('#logout').blur(function (){
    parent.location = 'http://' + host+ '/home';
    window.location = 'http://' + host+ '/home';
});
stormdrain
That would be a nice solution but I do need to be able to have multiple tabs open and working
Thqr
You can have as many tabs open as you want. It's just that if you click the logout button (either left click, or right-click) then click somewhere else, the redirect will happen.
stormdrain
I get nothing right clicking on it with your code?
Thqr
If you right-click the logout link and select 'open in new tab', then click on the new tab, then go back to the tab where you clicked the logout link, it should have re-directed to /home.
stormdrain