Im trying to create a sliding popup using jQuery in my drupal module .

Referring the code from:


My popup window, defined in the module, is a html string (using divs, a, img etc) .

How do I pass this html string to .js file. It gets used there in .get(url, function(data)).

Tried using drupal_to_js and drupal_json, both returns the value 0, not the string.
Need some suggestion on how to proceed.

2 Answers 2


You need

  1. a hook_menu() implementation that will provide you with the url:
  2. a page callback funtion that does print() or echo on the html snippet, then exit(). So no drupal_to_js() or drupal_json().

You can pass it using drupal_add_js


  // This will add variables in the Drupal.settings object
  drupal_add_js(array('my_module' => array('my_setting' => 'this_value')), 'setting');

You can access this variable like Drupal.settings.my_module.my_setting

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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