开发者

Javascript "<body onload=...>" in Drupal

I'm trying to integrate a javascript library for drag&drop on tables into one page of my custom Drupal module. I've included the js file using drupal_add_js, but I don't know how to ini开发者_JS百科tialize it.

The documentation for that library states that an init function should be called like

<body onload="REDIPS.drag.init()">

How would I do that in Drupal? Or has Drupal some better way of initializing the script?


Drupal has its own mechanism for this, involving adding a property to Drupal.behaviors. See this page: http://drupal.org/node/205296

Drupal.behaviors.redipsDragBehavior = function() {
    REDIPS.drag.init();
};

From the linked page:

Any function defined as a property of Drupal.behaviors will get called when the DOM has loaded.


You could try adding another drupal_add_js call in the same function as your other add_js:

drupal_add_js('REDIPS.drag.init();','inline','header',true);

The last param "true" is to defer the execution of the script. I hope that helps in some way!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜