1

I'm trying to add some mobile functionality to my Drupal site and need to bind some events in a "pageinit" function, NOT in a document ready, as the documentation says. Something like:

$(document).bind('pageinit', function(event){

// bind events

});

How do I do that in Drupal? Thanks a lot for your help!

4
  • Well how would you do it if your site wasn't Drupal? The answer is the same; javascript in Drupal is no different from javascript under any other system. If you need to know how to add custom Javascript to a page, please search the site as that question has been answered many times.
    – Clive
    Jan 22 '13 at 11:52
  • I would add something like what I posted in my message but I'm pretty sure Drupal 7 won't like that since the common use of document ready is something like: code (function ($) { Drupal.behaviors.something_here = { attach: function(context, settings) { ....
    – Teknotica
    Jan 22 '13 at 11:56
  • 1
    Ah ok...closures (that wrapper you're talking about) have nothing to do with Drupal (or jQuery for that matter). You can enable the $ variable in exactly the same way: (function($) { $(document).bind('pageinit', function(event){ ... }); })(jQuery);. If you don't need Drupal behaviours there's no reason to use them
    – Clive
    Jan 22 '13 at 11:59
  • Right. That make sense. Will try that. Thank you very much! :)
    – Teknotica
    Jan 22 '13 at 12:02

Your Answer

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

Browse other questions tagged or ask your own question.