-
Open All External Links in a New Window/Tab using jQuery
123$(document).ready(function() {$("a[href^='http']").not("[href*='mysite.com']").attr('target','_blank');});
123$(document).ready(function() {$("a[href^='http']").not("[href*='mysite.com'],[href*='mysite2.com']").attr('target','_blank');}); -
Add Javascript to a Specific Page
There are several ways to add javascript code to a page in Drupal. The method outlined below involves a modification to your theme’s template.php file. You’ll be editing (and un-commenting if necessary) your theme’s preprocess_page function. This basically lets you modify the variables that are available in your page.tpl.php file(s).
In the example below, I’ve checked if the page’s “is_front” property is true. You can use anything available in the $vars variable within the function. I suggest using the devel module to determine what variables are available. This can be done with: dpm($vars);
1234567891011121314/*** Override or insert variables into the page templates.** @param $vars* An array of variables to pass to the theme template.* @param $hook* The name of the template being rendered ("page" in this case.)*/function themename_preprocess_page(&$vars, $hook) {if ($vars['is_front']) {drupal_add_js(path_to_theme() . '/_javascript/homepage_rotate_bg.js', 'core');}$vars['scripts'] = drupal_get_js();} -
Dynamic and AJAX-driven Select Lists in Webform
This example is a two-for-one deal! I’m going to demonstrate how to
- dynamically populate a webform select list on page load
- dynamically populate a webform select list based upon the value chosen in another webform select list
For both parts of this example, the demo form I’ll be using is a “Get Started” form.