开发者

Change all href on page using Javascript or PHP

开发者 https://www.devze.com 2023-02-27 17:46 出处:网络
i need to change all links on a 开发者_运维技巧page to open an extra window when clicked, so <a href=\"http://www.foo.com\"></a>

i need to change all links on a 开发者_运维技巧page to open an extra window when clicked, so

<a href="http://www.foo.com"></a>

would become

<a href="#" onclick="window.open('http://www.bar.com');
    window.open('http://www.foo.com');">

preserving the previous URL, and opening the new link, simultaneously.

The new link would remain constant.


Using jQuery it would be something like

$('a').click(function() { window.open('...'); });


Try :

$(function(){
  $('a').attr('target','_blank');
});

This should do the trick.

I am using jQuery to set attribute "target" for every anchor tag on page, to "_blank".

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号