0
私はビデオを持っています。ユーザがホームページに上陸したときに自動再生したいです。ユーザーが自宅に戻ると、私はビデオを自動再生したくありません。クッキーを自動再生する<video> 1回の訪問につき1回のみ
これを次のスクリプトで設定しましたが、これは機能しません。
<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