[英]Can't Get document.getElementById(“wp_mep_1”).autoplay=false; to Execute after cookie is set
I Know the cookie is executing because I have the alert popping up. 我知道Cookie正在执行,因为我弹出了警报。 If i place
如果我放
document.getElementById("wp_mep_1").autoplay=false; 。的document.getElementById( “wp_mep_1”)自动播放= FALSE;
Outside of the if else statement then it will fire off and shut down the video. 在if else语句之外,它将触发并关闭视频。 Any suggestions on what is wrong with my code.
关于我的代码有什么问题的任何建议。 This is a nice piece of script for anybody that is trying to solve this problem with a video player that executes after visiting a page.
对于尝试使用访问页面后执行的视频播放器解决此问题的任何人来说,这都是一个不错的脚本。 Hope this helps someone besides me when I can get it fixed.
希望这可以对我以外的人有所帮助。
Thanks 谢谢
Here's the code. 这是代码。
<script> function setCookie(cname,cvalue,exdays) { var d = new Date(); d.setTime(d.getTime() + (exdays*24*60*60*1000)); var expires = "expires=" + d.toGMTString(); document.cookie = cname+"="+cvalue+"; "+expires; } function getCookie(cname) { var name = cname + "="; var ca = document.cookie.split(';'); for(var i=0; i<ca.length; i++) { var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1); if (c.indexOf(name) == 0) { return c.substring(name.length, c.length); } } return ""; } function checkCookie() { var user=getCookie("username2"); if (user != "") { alert("Welcome again " + user); document.getElementById("wp_mep_1").autoplay=false; } else { user = ("ACNEDominationVideo"); if (user != "" && user != null) { setCookie("username2", user, 30); } } } </script>
<!DOCTYPE html> <html> <body> <h1><span style="font-family: arial,helvetica,sans-serif; font-size: 52px;"><strong><div class="su-heading su-heading-style-default su-heading-align-center" style="font-size:22px;margin-bottom:20px"><div class="su-heading-inner"><span style="color: #ff0000; font-family: arial,helvetica,sans-serif; font-size: 32px;"> <span data-icon=""></span> Acne Domination Will Show You The Way <span data-icon=""></span> </div></div></span></strong></span></h1> <p style="text-align: center;"> <video id="wp_mep_1" src="http://acnedomination.101onlineorg.netdna-cdn.com/wp-content/uploads/videos/test2.mp4" width="740" height="360" controls="controls" preload="none" autoplay="true" > </body> <body onload="checkCookie()"> </html>
function setCookie(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
var expires = "expires=" + d.toGMTString();
document.cookie = cname + "=" + cvalue + "; " + expires;
}
function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') c = c.substring(1);
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
function checkCookie() {
var user = getCookie("AcneDominationVid");
if (user != "") {
//alert ("welcome");
var get = true;
if (get == true){
document.getElementById("wp_mep_1").autoplay=false;
}
} else {
user = ("ACNEDominationVideo3");
if (user != "" && user != null) {
setCookie("AcneDominationVid", user, 30);
}
}
}
checkCookie();
This fixes it. 这样就解决了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.