Question

I'm trying to stop a timer from running on a website. I either want to stop it or control its value. The timer id is:

id="timer"

I want to be able to stop it with a bookmarklet, so the code should begin with:

javascript:

I'm new to java, so I don't know the approach to stop a timer.

Was it helpful?

Solution

You are referring to Javascript, not Java. Javascript is incorporated into webpages and doesn't need to be installed. Java does need to install and is used for making applets. Two different things.

As for id="timer", you can set it's value using something like this.

javascript:document.getElementById("timer").innerHTML="Enter new value here";

But be aware that if it is counting down, there is probably a setInterval or setTimeout somewhere in the Javascript code of that page triggering it, and so the above bookmarklet will do nothing and can't do anything based on the information you've provided. One thing you could try is stopping all setTimeouts or setIntervals on the page, THEN calling the code above, but they may break something else in the page.

javascript:window.setTimeout = function(func, delay) {};window.setInterval = function(func, delay) {};document.getElementById("timer").innerHTML="Enter new value here";

To make them bookmarklets, just set those to the href attribute of a link, or type them in as URL of a bookmark.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top