How to open external links in a new window in Drupal
On:
Wednesday, August 20, 2008 - 10:47
Create a file containing this piece of javascript.
if (Drupal.jsEnabled) {
$(document).ready(function() {
$("a[@href^=http]").each(function() {
if(this.href.indexOf(location.hostname) == -1) {
$(this).click(function(){window.open(this.href);return false;});
}
});
});
}Next in your phptemplate_variables function located in the template php you add the code in this example function.
<?php
function _phptemplate_variables($hook, $vars) {
if ($hook == 'page') {
drupal_add_js(path_to_theme().'/js/scripts.js');
$vars['scripts'] = drupal_get_js();
return $vars;
}
return array();
}
?>
Add new comment