In my module, I add javascript with a url parameter:

drupal_add_js(libraries_get_path('mylibrary') . '/MyLibrary.js?config=MY_CONFIG_PARAM');

When I view the HTML page source, the line loading the script looks like this:

<script src="http://example.com/sites/all/libraries/mylibrary/MyLibrary.js%3Fconfig%3DMY_CONFIG_PARAM&amp;nbbffw"></script>

The '?' and '=' are encoded. Trying to load this script results in an error, because browser can't find it (but if I manually decode it in the browser bar, it's found).

How to add javascript with a parameter, so that it won't get encoded?


Try this code

    libraries_get_path('mylibrary') . '/MyLibrary.js', 
      'query' => array(
        'config' => MY_CONFIG_PARAM
  • there is still a little problem. I didn't notice it before. At the and of my example HTML code you see MY_CONFIG_PARAM&amp;nbbffw which probably gets added by caching system (I am not sure). Do you know if this is correct and in case it's not, how to get it correct? (I had problem with browser caching even after clearing Drupal cache and browser cache and suspect it might be the reason, although not sure) – camcam Sep 3 '14 at 12:39

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.