There is a site directory made on bootstrap. In the catalog, each link leads to its own page. In each link, the target = _blank attribute is set so that each page opens in a new tab. However, on mobile phones it is necessary that this attribute should not be as in mobile browsers in this case the return arrow to the previous page is not active.

The option to draw two links for small screens and large screens will not work as this will not have a very good effect on seo as I understand it.

  • We define that the client sits from the mobile phone, we remove the target attribute. $ ('div'). removeAttr ('targer') - G.Denis
  • and I would recommend to remove target="_blank" from all internal links of the site, because it has long been common in the development of the RuNet that all internal links open in the same window, unless of course you are making a site for China, there’s a different concept - MasterAlex
  • also began to lean towards this option, but where is it written about? - heff
  • @MasterAlex therefore Yandex as the banner of the RuNet, opens all the links in a new window - L. Vadim
  • @heff How do you like my script? Helped? - L. Vadim

1 answer 1

We check the width of the window, if it is equal to 400 or the width is different, what you need, then we change the attribute. All links on the site.

 $(document).ready(function(){ if($(window).width() == 400) { $('body').find('a').each(function() { $(this).attr('target',"_self"); }); } }); 
  • honestly did not try, made internal links open in a new window. - heff
  • well, this is the complete answer to your question, try it - L. Vadim
  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - L. Vadim