Path to drupal module from inside of javascript
Is there a way to get the drupal(7) module path from which the .js was loaded?
I know that JS is a front-end language, but possibly Drupal passes that info in the Drupal object somehow?Basicly I want to do something like this:
$('#selectable_html').load("selectable_html.html");
But since Drupal constructs pages on the fly this request transforms to "http://___/node/add/selectable_html.开发者_如何学Chtml"
, which is obviously wrong.
You can pass things to Javascript via Drupal using drupal_add_js using the 'setting' option.
Add settings ('setting'): Adds settings to Drupal's global storage of JavaScript settings. Per-page settings are required by some modules to function properly.
drupal_add_js(array('myModule' => array('key' => 'value')), 'setting');
You could then pass the path returned from drupal_get_path('module', 'name') and access it in Javascript using Drupal.setting.
All settings will be accessible at Drupal.settings.
精彩评论