www.webdeveloper.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 19

Thread: Limit Button to 6 clicks per hour

  1. #1
    Join Date
    Mar 2013
    Location
    Great Falls, MT
    Posts
    24

    Limit Button to 6 clicks per hour

    Hello,

    I am building an internet radio application. I need to limit the skip button to 6 skips per hour.

    Every time you skip a song, the number will decrease by one (1), until it reaches zero (0). When reaching 0, a message will appear reminding you that you have exceeded your skip allotment for the hour. As time goes forward, the skip counter will begin counting up, back to 6.

    Can someone help me with this? Willing to pay for quality help.

  2. #2
    Join Date
    Jul 2013
    Posts
    13
    Hello,

    This is only base of user IP...

    Thanks

  3. #3
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,318
    Someone only needs to disable JavaScript and then your stuffed...

    I suggest that you do something like

    Code:
    window.onload = function(){
    
     button = document.getElementById("clickme");
     button.onclick = function(){
     
     		var clicks = parseInt(this.value);
    		clicks--;
    		if(clicks>=0)
    			this.value = ""+clicks+" Clicks left";
     
     	}
    
    }
    Then the button

    HTML Code:
    <input id="clickme" name="button" type="button" value="6 Clicks left" />
    if you have to limit clicks and are not worried about JS being disabled

    your job now is to work out how to time limit and stop the window refreshing, that would be something to do with window.onunload
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  4. #4
    Join Date
    Mar 2013
    Location
    Great Falls, MT
    Posts
    24
    Thank you for your response. Still unclear on how that would work, do you have to use window.onunload to prevent clicks from being reset? Sorry, I don't have much experience writing script.

    I'm not too concerned about the user having javascript disabled we can make sure that they know they have to use it.

  5. #5
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,318
    Can you clarify what your aims are in regard to the limitation of clicks, what is it your trying to protect, I ask because JavaScript is not considered in any way, shape or form as a suitable method of protection of anything.

    If you can let people reading the thread know what your aims and intentions are, it might help because alternative methods of dealing with your requirements may exist.
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  6. #6
    Join Date
    Mar 2013
    Location
    Great Falls, MT
    Posts
    24
    What I have is a website that uses a jPlayer to play music. The website will serve as a music solution for establishments and businesses. In order to be legal and limit the user from skipping through the entire playlist the users must not be able to skip songs more than 6 times in an hour. Examples of this can be seen on Slacker and Radio.com's player. Radio.com uses a flash player and Slacker uses some functions built into their player.

    Hopefully that clears things up a little.

  7. #7
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,373

    Lightbulb

    This is not an entire solution to your problem, but it might give you some ideas...

    For testing purposes, the program only allows for 6 clicks within 1 minute (60 seconds) rather than 60 minutes.

    Code:
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8" />
    <title> Untitled </title>
    </head>
    <body>
    <button id="skipBtn" onclick="countSkips(this)" value="6">6 skips left</button>
    
    <script type="text/javascript">
    // For: http://www.webdeveloper.com/forum/showthread.php?285027-Limit-Button-to-6-clicks-per-hour&p=1292561#post1292561
    
    function countSkips(cntInfo) {  // alert(cntInfo.id+', '+cntInfo.value+', '+cntInfo.innerHTML); 
      var currentTime = new Date();
      var timeInfo = new Date();
    
    // logic for 60 minutes
    //  timeInfo = 3600 - parseInt((currentTime.getTime() - startTime.getTime()) / 1000);
    //  var timeLeft = parseInt(timeInfo/60)+':'+timeInfo%60;
    //  if (timeInfo < 0) { cnt = 7;  cntInfo.value = cnt; timeLeft = 3600; startTime = currentTime; }
    
    // logic for 60 seconds (for testing purposes)
      timeInfo = 60 - parseInt((currentTime.getTime() - startTime.getTime()) / 1000);
      var timeLeft = '0:'+timeInfo%60;
      if (timeInfo < 0) { cnt = 7;  cntInfo.value = cnt; timeLeft = 60; startTime = currentTime; }
    
      var cnt = cntInfo.value;
      if (cnt > 0) {
        cnt--; cntInfo.value=cnt;  cntInfo.innerHTML=cnt+' skips left';
      } else {
        alert('No more skips allowed for 1 (minute | hour)\nTime left: '+timeLeft);
        if (cnt == 0) { starttime = currenttime;  cnt--; }
      }
    }
    
    var startTime = new Date();
    </script>
    
    </body>
    </html>
    Current problem to solve is the case where the use leaves the program
    and comes back later or just refreshes the screen.
    Boom, the starttime and counter values are reset to their original conditions.

    To solve this, I would add some code for a cookie or local storage value that retains the start time.
    Then, when the user returns, the saved time value can be used as the start time rather than it being reset.
    This logic is NOT included, but cookies and local storage scripts abound on the web.

  8. #8
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,318
    I have never ever in all the years of being around audio heard of a clause for being legal to limit the ability to skip ahead in a track. Could you please cite the source of this legislative requirement?
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  9. #9
    Join Date
    Mar 2013
    Location
    Great Falls, MT
    Posts
    24
    Pandora, Slacker, Radio dot com, Last.fm, among many other broadcasters abide by this law.

    "When you listen to Last.fm radio, there is a limit on the number of times you can skip tracks on each station. Itís a requirement of our licensing agreements that allow us to stream music legally.

    Quote Originally Posted by \\.\ View Post
    I have never ever in all the years of being around audio heard of a clause for being legal to limit the ability to skip ahead in a track. Could you please cite the source of this legislative requirement?

  10. #10
    Join Date
    Mar 2013
    Location
    Great Falls, MT
    Posts
    24
    Thank you JMRKER, going to test and see what we can do about storing startTime.

  11. #11
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,318
    What you are referring to is a limit imposed by the RIAA, and the limitation IMHO is like most things, orientated towards advertisers not being missed, people do hate adverts and therefore it is quite reasonable to say that if you are carrying paid adverts where you are the revenue earner, then you would have to comply otherwise you could tell the RIAA to whistle.

    People often confuse what is the law and what others say is the law and people do not challenge authority enough by asking to be given the legislative passage that gives them the tight to wade in and be the big bully.

    You mention that you are using web player that I know carries video... well if you have got video streaming with the audio, your not breaking any laws or rules by allowing people to skip ahead as often as they like, the rules do not apply to video streams. <-- Hint
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  12. #12
    Join Date
    Mar 2013
    Location
    Great Falls, MT
    Posts
    24
    That doesn't apply here. Bypassing this all together is a nice thought, but unfortunately it's not an option.

  13. #13
    Join Date
    Mar 2013
    Location
    Great Falls, MT
    Posts
    24
    Do you think storing the script with basket.js would work for saving the variables? Or would it be better in database?

    Quote Originally Posted by JMRKER View Post
    This is not an entire solution to your problem, but it might give you some ideas...

    For testing purposes, the program only allows for 6 clicks within 1 minute (60 seconds) rather than 60 minutes.

    Code:
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8" />
    <title> Untitled </title>
    </head>
    <body>
    <button id="skipBtn" onclick="countSkips(this)" value="6">6 skips left</button>
    
    <script type="text/javascript">
    // For: http://www.webdeveloper.com/forum/showthread.php?285027-Limit-Button-to-6-clicks-per-hour&p=1292561#post1292561
    
    function countSkips(cntInfo) {  // alert(cntInfo.id+', '+cntInfo.value+', '+cntInfo.innerHTML); 
      var currentTime = new Date();
      var timeInfo = new Date();
    
    // logic for 60 minutes
    //  timeInfo = 3600 - parseInt((currentTime.getTime() - startTime.getTime()) / 1000);
    //  var timeLeft = parseInt(timeInfo/60)+':'+timeInfo%60;
    //  if (timeInfo < 0) { cnt = 7;  cntInfo.value = cnt; timeLeft = 3600; startTime = currentTime; }
    
    // logic for 60 seconds (for testing purposes)
      timeInfo = 60 - parseInt((currentTime.getTime() - startTime.getTime()) / 1000);
      var timeLeft = '0:'+timeInfo%60;
      if (timeInfo < 0) { cnt = 7;  cntInfo.value = cnt; timeLeft = 60; startTime = currentTime; }
    
      var cnt = cntInfo.value;
      if (cnt > 0) {
        cnt--; cntInfo.value=cnt;  cntInfo.innerHTML=cnt+' skips left';
      } else {
        alert('No more skips allowed for 1 (minute | hour)\nTime left: '+timeLeft);
        if (cnt == 0) { starttime = currenttime;  cnt--; }
      }
    }
    
    var startTime = new Date();
    </script>
    
    </body>
    </html>
    Current problem to solve is the case where the use leaves the program
    and comes back later or just refreshes the screen.
    Boom, the starttime and counter values are reset to their original conditions.

    To solve this, I would add some code for a cookie or local storage value that retains the start time.
    Then, when the user returns, the saved time value can be used as the start time rather than it being reset.
    This logic is NOT included, but cookies and local storage scripts abound on the web.

  14. #14
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,373
    Quote Originally Posted by dardisintel View Post
    Do you think storing the script with basket.js would work for saving the variables? Or would it be better in database?
    Have not a clue as to what 'basket.js' does.
    Not enough information provided.

  15. #15
    Join Date
    Mar 2013
    Location
    Great Falls, MT
    Posts
    24
    Sorry, I'm looking for one of these local storage scripts you were talking about?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles