Overwrite Drupal jQuery behaviors on specific pages

I recently ran into a situation that required me to disable a jQuery function on one specific Drupal page. I searched for keywords like "detach drupal behavior" and "disable jQuery function in drupal," but to no avail. So I came up with a fairly simple workaround that uses the JS Injector module.

I've used this to Disable Beauty Tips, Compact Forms, and even Drupal's core password checker on specific pages.

First, I found the function that I wanted to overwrite. In my case, I wanted to disable the jQuery generated by the Compact Forms module on a specific webform. So I cracked open the compact_forms js file and found the jQuery function that actually does the magic: "Drupal.behaviors.compactForms()"

After enabling the JS Injector module, I created a new injection rule: Drupal.behaviors.compactForms = function (context) { return; };

This simply redefined thecompactForms() function as an empty function-- therefore preventing the offending code from running when called.

I then unchecked "Preprocess js" checkbox for this rule so that my new rule was sure to be called last, and would therefore overwrite the original function.

Lastly, I specified that this rule only be active on the desired pages.

Not too difficult, right?

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.