Search code examples
phpjavascripthref

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.


Solution

  • Using jQuery it would be something like

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