开发者

With Jquery .click() can I also catch opening in a new tab or window?

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"


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';
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜