Community Documentation

Valid XHTML link popups using jQuery

Last updated July 25, 2008. Created by aj045 on November 15, 2006.
Edited by tanepiper. Log in to edit this page.

Instead of using a link target which breaks XHTML 1.1 validity, you can create a popup link using jQuery.

To do this, you can use XPATH in jQuery functions

Now, in your template file (e.g. node.tpl.php) insert this code:

<?php
drupal_add_js
('
$(document).ready(function(){
  $("a[@href^=http:]").click(function() {
    window.open(this.href);
    return false;
  });
});'
, 'inline' );
?>

Now all external links on your site will pop up in a new window, but internal links will not be affected, provided they are not programmed with "http:" in front of them (most Drupal automatic links are not).

About this page

Drupal version
Drupal 4.7.x, Drupal 5.x
Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.
nobody click here