OK, some I'm using jPlayer for some music on my site, and I have an opt out functionality that I would like to implement here, but I need a little help getting started.
So, I've set a cookie:
$.cookie('autoPlay', 'no', { expires: 365 * 10 });
So, I like to set up a conditional as follows:
if(cookie == 0) {
noMusic;
} else {
playMusic
}
The reason I have it set up like this, is so that it autopl开发者_开发知识库ays by default, and only doesn't autoplay if you opt out. Because, when opting out of my service, you are given the choice of navigating the site "Without Music" or "With Music". Therefore, I just leave the cookie be if the end-user chooses "With Music", but set it to a certain value only if they opt out by choosing "Without Music", therefore, it'll autoplay by default.
I need some help with my assignment condition for the if statement however. I'm a little unused to jQuery's syntax with this.
Also, I need to find out how to not play the music, and how to specify to play it. I need to grab the right piece of code form the jPlayer plugin I guess.
Any help is awesome and appreciated!
Thanks!
Haven't tested this, but its worth a try:
wherever your music player goes:
<?php if($_COOKIE['autoplay'] == 'no'){
//no music
} else {
setcookie("autoplay", "yes", time()+3600);
?>
<div id="musicplayer">
The code that runs your musicplayer goes here
</div>
<?php } ?>
Then, you create a button that allows them to opt out:
<a href="#" onClick="setCookie('autopsy','no'); document.location.href='http://yourdomain.com';">Sweet lord of music please stop playing the 8-bit track when I click on thine button</a>
精彩评论