0

I have been asked to include an external js file into a site where I don't have direct access to modify it and the generated script has jQuery it that references $.

Is it possible to include this without modifying the source js file?

I've added it as below

drupal_add_js("www.domain.com/my.js", array(
      'type' => 'external',
      'scope' => 'header',
      'group' => JS_LIBRARY,
      'every_page' => TRUE,
      'weight' => -1,
    ));

But I get undefined errors due to the use of $

Cheers

  • 1
    Sure, add $ = jQuery somewhere before that script loads; but bear in mind you'll break jQuery no conflict, whether that causes problems depends on what other JS your site needs. This is really more of a JS question rather than a Drupal one – Clive Apr 22 '16 at 12:12
1

One way to circumvent this would be by installing the jQuery Dollar module.

This would allow you to avoid $ conflicts.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.