【问题标题】:The music should only automatically go on the first time enter the website音乐应该只在第一次进入网站时自动播放
【发布时间】:2014-11-03 20:44:22
【问题描述】:

我在主页中使用以下代码作为背景音乐

<object type="application/x-shockwave-flash" data="/Music/dewplayer-mini.swf" align="right"    width="100" height="20" id="dewplayer" name="dewplayer">
<param name="movie" value="/Music/dewplayer-mini.swf" />
<param name="flashvars" value="mp3=/Music/demo.mp3&amp;autostart=1&amp;autoreplay=1" />
<param name="wmode" value="transparent" />
</object>

目前音乐将在首页播放。 当我从子页面重新访问主页时,我不希望播放音乐。

我可以使用 cookie 或 session 吗? 有什么帮助吗?

【问题讨论】:

    标签: jquery html html5-video


    【解决方案1】:
    <html>
        <head>
            <link rel="stylesheet" type="text/css" href="app.ui.css" />
            <script src="http://code.jquery.com/jquery.min.js"></script>
            <script src="https://raw.githubusercontent.com/carhartl/jquery-cookie/master/src/jquery.cookie.js"></script>
            <script>
                $(function(){
                    if($.cookie('firstVisit')==undefined){
                        $.cookie('firstVisit','true');
                    }else{
                        $.cookie('firstVisit','false')
                    }
                    var firstVisit = $.cookie('firstVisit');
                    if(firstVisit=='true'){
                        $('#welComeVideo').show();
                    }else{
                        $('#welComeVideo').hide(); 
                    }
                })
            </script>
        </head>
        </body>
    
        <div id="welComeVideo" style="display:none;">
            <object type="application/x-shockwave-flash" data="/Music/dewplayer-mini.swf" align="right"    width="100" height="20" id="dewplayer" name="dewplayer">
                <param name="movie" value="/Music/dewplayer-mini.swf" />
                <param name="flashvars" value="mp3=/Music/demo.mp3&amp;autostart=1&amp;autoreplay=1" />
                <param name="wmode" value="transparent" />
            </object>
        </div>
        </body>
    </html>
    

    请试试这个

    【讨论】:

      【解决方案2】:

      您可以使用session cookie

      然后仅当 cookie 不存在/设置时才使用 javascript 播放音乐

      How to Play a Flash Movie with JavaScript in Firefox

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-05-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多