Change all href on page using Javascript or PHP
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".
精彩评论