简体   繁体   English

有没有办法只为重定向的链接制作“target='_blank'”?

[英]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.我正在开发一个 spring mvc 项目,其中有一个场景,单击按钮视图会显示在同一选项卡中。 but in certain scenario it is redirected to another url.但在某些情况下,它被重定向到另一个 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 .结论如果有 url 重定向,我想知道是否有任何方法可以在新选项卡中打开,否则在同一选项卡中打开

This will alter all your links, adding target="_blank" to them if they do not share your domain, if that is what you mean:这将改变您的所有链接,如果它们不共享您的域,则向它们添加 target="_blank" ,如果这就是您的意思:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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