简体   繁体   中英

Is there a way to make "target='_blank'" only for the redirected links?

I am working on a spring mvc project where there is one scenario that on click of a button view is displayed in the same tab. but in certain scenario it is redirected to another url. so at this time when there is redirect i want to open in new tab.

conclusion : I want to know whether there is any way to open in new tab if there is url redirection otherwise open in the same tab .

This will alter all your links, adding target="_blank" to them if they do not share your domain, if that is what you mean:

var slice = location.href.split('/');
var domain = slice[1] ? slice[0] : slice[2];
$('a').each(function()
{
    if (this.href.indexOf(domain) < 0)
    {
        $(this).attr('target','_blank');
    }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM