Open all links in new tabs with jQuery

后端 未结 5 978
面向向阳花
面向向阳花 2021-01-11 19:06

I have some links that are placed in my page dynamically via JSON and have no way to directly edit them. I want to force all links to open in new tabs, ala target=\"_b

5条回答
  •  旧巷少年郎
    2021-01-11 19:53

    You could do this (which lets the users browser decide whether to open a new window or tab)

    $('a').live('click', function() {
        window.open($(this).attr('href'));
        return false;
    });
    

提交回复
热议问题