如何将我的Javascript插入我的Drupal站点/节点

时间:2013-11-01 17:23:53

标签: javascript drupal cookies

我正在尝试插入由视频主机提供的Cookie,该视频主机将恢复用户离开的视频。他们有一个明显有效的例子。当尝试将其插入我的Drupal站点时,cookie将无法正常工作。视频刚开始时就开始了。

我启用了“PHP输入过滤器”,因为我读到我需要为drupal插入脚本。请参阅下面我的节点中的代码。

任何人都可以帮我弄清楚为什么这不起作用,如何让它工作,或者用Drupal做更好的方法?

谢谢,

<script type="text/javascript">

wistiaEmbed.ready( function() {
  var all_cookies = document.cookie.split(';'), // gets the value of the cookies on the     page
    cookie_str = "resume_video=",
    resume_cookie = does_resume_cookie_exist(all_cookies);


  function does_resume_cookie_exist(cookie_arr) {
    var i, curr_string, found;
      for (i = 0; i < cookie_arr.length; i++) {
      curr_string = cookie_arr[i];
        if (curr_string.substring(0,5) === cookie_str.substring(0,5)) {
          // we've found it!
          found = curr_string;
          break;
        }
      }
    return found;
  }

  function set_cookie_time(t) {  
    document.cookie = cookie_str + t.toString(); // this takes the time (t) and sets the cookie with that time  
  }

  if (resume_cookie) {
    num = resume_cookie.split('=')[1];
    start_time = parseInt(num);
    wistiaEmbed.time(start_time).play(); // plays the video at the specific time defined in the cookie upon return to the page
  } else {
   set_cookie_time(0);  // places a cookie on the visitor
    wistiaEmbed.play();  // starts the video from the beginning
  }
  wistiaEmbed.bind("timechange", function(t) { // on timechange, reset cookie
    set_cookie_time(t);
  });
  wistiaEmbed.bind("end", function() { // if person has watched the entire video, sets the video to beginning upon retun
    set_cookie_time(0);
  });
});
</script>

<div id="wistia_npcc5k96s9" class="wistia_embed"         style="width:640px;height:508px;"> </div>
 <script charset="ISO-8859-1" src="http://fast.wistia.com/assets/external/E-v1.js">  </script>
     <script>
wistiaEmbed = Wistia.embed("npcc5k96s9");
</script>**strong text**

1 个答案:

答案 0 :(得分:0)

你使用的是什么版本的drupal?您提供的代码是否实际在请求响应中输出?

有几种解决方案(IMO)。

希望有所帮助。