0
사용자가 홈페이지를 방문하면 자동 재생할 동영상이 있습니다. 사용자가 다시 집으로 클릭하면 동영상이 자동 재생되는 것을 원하지 않습니다.쿠키를 자동 재생 <video> 방문당 한 번만
이 스크립트는 다음 스크립트로 설정했지만 작동하지 않습니다.
<script type="text/javascript" language="Javascript">//
function played(){
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,c.length);
if (c.indexOf("played=") == 0) return 1;
}
var date = new Date();
var days = 7;
date.setTime(date.getTime()+(days*24*60*60*1000));
document.cookie = "played=1"+"; expires="+date.toGMTString()+"; path=/";
return 0;
}
if(played()==0){
document.write("<video controls poster=\"http://acceptdifference.org.au/wp-content/uploads/2016/07/Accept-difference-fallback.jpg\" class=\"fillWidth\"><source src=\"https://s3-ap-southeast-2.amazonaws.com/acceptdifference/30sec_14_07_Youtube_ClosedCaptions.mp4.mp4\" /><source src=\"https://s3-ap-southeast-2.amazonaws.com/acceptdifference/30sec_14_07_Youtube_ClosedCaptions.webmhd.webm\" /><source src=\"https://s3-ap-southeast-2.amazonaws.com/acceptdifference/30sec_14_07_Youtube_ClosedCaptions.oggtheora.ogv\" /><img src=\"http://acceptdifference.org.au/wp-content/uploads/2016/07/Accept-difference-fallback.jpg\" title=\"Your browser does not support the video tag\"></video>");
}
else
{
document.write("<video controls autoplay poster=\"http://acceptdifference.org.au/wp-content/uploads/2016/07/Accept-difference-fallback.jpg\" class=\"fillWidth\"><source src=\"https://s3-ap-southeast-2.amazonaws.com/acceptdifference/30sec_14_07_Youtube_ClosedCaptions.mp4.mp4\" /><source src=\"https://s3-ap-southeast-2.amazonaws.com/acceptdifference/30sec_14_07_Youtube_ClosedCaptions.webmhd.webm\" /><source src=\"https://s3-ap-southeast-2.amazonaws.com/acceptdifference/30sec_14_07_Youtube_ClosedCaptions.oggtheora.ogv\" /><img src=\"http://acceptdifference.org.au/wp-content/uploads/2016/07/Accept-difference-fallback.jpg\" title=\"Your browser does not support the video tag\"></video>");
}
</script>
을 반환 단순히 myVideo.play()를 호출하면됩니다. 훨씬 더 간단합니다. –
http://stackoverflow.com/questions/29986657/global-variable-usage-on-page-reload/ – guest271314