0

So I need some help.. I have a page which has this play button, which should start playing its page siblings. And a pause button which should stop the playing. But that's not the problem, I have it figured out.

The problem is that How could I set the pause button to actually pause this :

  setTimeout(function() {   
  window.location.href = "<?php echo get_permalink($nextID);?>";
}, 2000);

I was thinking of making this with cookies, the idea is this : when you enter the page, the cookie's value is set to 1 as a default. And when the default number is true, that above code will start playing the pages after x amount of seconds. And IF the pause button is pressed, the cookie's value is set to 0, and the pages will not play.

And yeah, again if play is pressed it sets the cookie's value to 1.

But that's just my idea, please help!

Thanks for advance!

-Kev

3 Answers 3

1

Try something like this

var timer;

function playPage(){
  timer = setTimeout(function() {   
    window.location.href = "<?php echo get_permalink($nextID);?>";
  }, 2000);
}

$pauseButton.click(function(){ clearTimeout(timer); });

$playButton.click(playPage);
Sign up to request clarification or add additional context in comments.

2 Comments

Problem is with this that, when the user wants to change the page, the timer is back on, but I need a solution that will stop the timer at that page and what ever he chooses to click on. Thanks man!
Than just do clearTimeout(timer) only which will stop timer and than user can choose what to click? If you create a demo that will be helpful.
0

I suggest you to rather do it with a hidden field. on load set the value of this field to 1. and when the pause is clicked set it to 0. on click check the values of this hidden field to play and pause accordingly

2 Comments

Can you give me an example?
sorry I was suggesting hidden field while staying on current page only . your requirement seems that you also need to go to a different page. in that case ,yes. set a cookie.
0
window.location.href = "<?php echo get_permalink($nextID);?>";

This code above may not work. PHP code will not run in your browser. To work with cookies you can try this lib: http://plugins.jquery.com/cookie/

1 Comment

You can mix php in javascript as long as the PHP function returns a string properly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.