Drupal如何制作弹出窗口?

时间:2016-02-19 15:39:36

标签: javascript drupal-7 popup head

我是Drupal的新手,我刚刚第一次在本地安装了Drupal。 我想在加载页面时弹出一个弹出窗口,这将导致我创建的文章。

我看到了一种使用我在网上找到的代码的方法:

<!DOCTYPE html>
<html>
  <head>
    <meta charset=utf-8 />
    <title>ColorBox demo</title>
    <link rel="stylesheet" href="http://www.jacklmoore.com/colorbox/example1/colorbox.css" />
  </head>
  <body>
    <h1>Hello, there!</h1>
    <h2>This is some content</h2>
    <p>The popup will open in five seconds</p>

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    <script src="http://www.jacklmoore.com/colorbox/jquery.colorbox.js">    </script>
    <script>
      function openColorBox(){
        $.colorbox({iframe:true, width:"80%", height:"80%", href: "http://www.sitepoint.com"});
      }

      setTimeout(openColorBox, 5000);
    </script>
  </body>
</html>

虽然这个代码在我自己测试时似乎有效,但我不知道如何编辑Drupal页面的head和body部分。有没有办法实现这个或其他方式来制作弹出窗口?

1 个答案:

答案 0 :(得分:0)

首先应安装colorbox模块:
https://www.drupal.org/project/colorbox

然后在你的template.php中,你可以用这种方式添加内联脚本:

drupal_add_js('jQuery(document).ready(function () {function openColorBox(){
    $.colorbox({iframe:true, width:"80%", height:"80%", href: "http://www.sitepoint.com"});
  }setTimeout(openColorBox, 5000); });', 'inline');