最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

ajax - Path to drupal module from inside of javascript - Stack Overflow

programmeradmin1浏览0评论

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.html", which is obviously wrong.

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.html", which is obviously wrong.

Share Improve this question edited Feb 26, 2014 at 16:12 Robbert 6,6026 gold badges37 silver badges64 bronze badges asked Jul 28, 2011 at 12:17 NoRiMNoRiM 435 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

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.

发布评论

评论列表(0)

  1. 暂无评论