无法获取document.getElementById(" wp_mep_1")。autoplay = false;设置cookie后执行

时间:2015-01-29 02:15:58

标签: javascript getelementbyid

我知道cookie正在执行,因为我已经弹出警报。如果我放置

的document.getElementById(" wp_mep_1&#34)。自动播放= FALSE;

在if else语句之外,它将启动并关闭视频。关于我的代码有什么问题的任何建议。对于试图通过访问页面后执行的视频播放器来解决此问题的任何人来说,这是一个很好的脚本。希望这可以帮助我以外的人,当我能修复它。

由于

这是代码。



<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>
&#13;
<!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="&#xe044;"></span> Acne Domination Will Show You The Way <span data-icon="&#xe044;"></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>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

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(); 

这解决了它。