zoukankan      html  css  js  c++  java
  • [Drupal] How to add the js file and js code block in Drupal

    Drupal 6:

     代码

      // This will add a JS file to your head (specifically the $scripts variable in page.tpl.php)
      drupal_add_js(drupal_get_path('module', 'my_module'. '/my_module.js');

      
    // This add inline JS to the head of the document
      drupal_add_js('alert("Hello!")', 'inline');

      
    // This will add variables in the Drupal.settings object
      drupal_add_js(array('my_module' => array('my_setting' => 'this_value')), 'setting');
      
      
    //add an external JS file to your site.
      //You can not add <script XXXX  />, but you have to add as <script XXX></script>,
      //because the first one will cause some problem (webkit-base browser)

      drupal_set_html_head('<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>');

     Drupal 7:

    代码
      drupal_add_js('misc/collapse.js');
      drupal_add_js(
    'misc/collapse.js', 'file');
      drupal_add_js(
    'jQuery(document).ready(function () { alert("Hello!"); });', 'inline');
      drupal_add_js(
    'jQuery(document).ready(function () { alert("Hello!"); });',
        
    array('type' => 'inline', 'scope' => 'footer', 'weight' => 5)
      );
      drupal_add_js(
    'http://example.com/example.js', 'external');
      drupal_add_js(
    array('myModule' => array('key' => 'value')), 'setting');

    Details: http://api.drupal.org/api/drupal/includes--common.inc/function/drupal_add_js 

  • 相关阅读:
    继承关系·
    对象第复制operator=
    关于类拷贝造函数
    静态数据成员与静态成员函数
    linux新内核的时钟机制代码
    RTC系统
    Android关机闹钟实现
    更改printk打印级别
    vncserver 配置全屏显示
    vnc里鼠标拖动终端就会产生ctrl+c终端
  • 原文地址:https://www.cnblogs.com/davidhhuan/p/1905672.html
Copyright © 2011-2022 走看看