jQuery: go to URL with target=“_blank”

后端 未结 7 1965
悲哀的现实
悲哀的现实 2020-12-04 15:12

I am using this bit of jQuery code to get href of the link:

var url = $(this).attr(\'href\');

-- and this bit of code to go to that href:

7条回答
  •  长情又很酷
    2020-12-04 16:01

    Use,

    var url = $(this).attr('href');
    window.open(url, '_blank');
    

    Update:the href is better off being retrieved with prop since it will return the full url and it's slightly faster.

    var url = $(this).prop('href');
    

提交回复
热议问题