Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将Javascript插入Drupal站点/节点_Javascript_Drupal_Cookies - Fatal编程技术网

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

如何将Javascript插入Drupal站点/节点,javascript,drupal,cookies,Javascript,Drupal,Cookies,我正在尝试插入一个由视频主机提供的cookie,该cookie将恢复用户停止的视频。他们有一个明显有效的例子。当尝试将其插入我的Drupal站点时,cookie将无法工作。视频从一开始就开始了 我启用了“PHP输入过滤器”,因为我读到drupal需要这样做才能插入脚本。请参阅下面我的节点中的代码 有谁能帮我弄清楚为什么这不起作用,如何让它起作用,或者用Drupal做这件事的更好方法吗 谢谢, <script type="text/javascript"> wistiaEmbed.r

我正在尝试插入一个由视频主机提供的cookie,该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**

wistiaEmbed.ready(函数(){
var all_cookies=document.cookie.split(“;”),//获取页面上cookie的值
cookie_str=“resume_video=”,
resume\u cookie=是否存在(所有cookie);
函数是否恢复\u cookie\u存在(cookie\u arr){
变量i,当前字符串,已找到;
对于(i=0;i
您使用的是什么版本的drupal?您提供的代码是否在请求-响应中实际输出

有几种解决方案(IMO)

  • 如果代码出现在响应中,则可能是其他javascript错误导致代码无法执行
  • 如果该代码片段适用于该类型的所有节点,则可以使用node_view挂钩将代码注入该节点类型,例如(我假设为D7):

    这里有一份推荐信可以帮助你

  • 类似地,您可以使用主题钩子(可能是钩子预处理)在主题层注入代码片段


希望能有所帮助。

我感谢您的意见。那么我会把它放到我的html.tpl.php文件中吗?另外,我把它放在了我的个人网站上(我正在使用它进行测试),所以我很兴奋。然后,我将在我个人网站上工作的脚本插入到我客户的生产网站中,但它在我客户的生产网站上不工作。视频在我的网站上恢复得很完美,但在客户网站上,它仍然从重访开始。有什么想法吗?我很高兴为您提供这两个站点的URL,以便您可以看到它们的行为。再次感谢!哦,我是D7。是的,也许一个我们可以看到错误代码的示例链接会有所帮助。
function mymodule_node_view($node, $view_mode)
{
    if($node->type =='video_page')
    {
        drupal_add_js('resume_video.js'); // this js holds your code snippet
    }
}