我正在尝试插入由视频主机提供的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**
答案 0 :(得分:0)
你使用的是什么版本的drupal?您提供的代码是否实际在请求响应中输出?
有几种解决方案(IMO)。
如果该代码片段适用于该类型的所有节点,则可以使用node_view钩子将代码注入该节点类型,例如(我假设为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
}
}
这是一个可以帮助你的参考 https://api.drupal.org/api/drupal/modules%21node%21node.api.php/function/hook_node_view/7
你可以使用主题钩子在主题层注入那段代码,可能是hook_preprocess https://api.drupal.org/api/drupal/modules!system!theme.api.php/function/hook_preprocess/7
希望有所帮助。