-2

I am more or less a complete beginner. What I want to do is use a bookmarklet to capture when a specific html button on a page is clicked and then start a timer. How would I go about that in javascript?

cats00eye
  • 3
  • 1

1 Answers1

0

You can use generators like this to convert your JavaScript into a bookmarklet.

Example:

This script logs the first button on the page when it's clicked:

document.querySelector("input[type=button]").onclick=function(e){
    console.log(e)
}

And after conversion, this bookmarklet does the same after injected into a page.

javascript:(function()%7Bdocument.querySelector(%22input%5Btype%3Dbutton%5D%22).onclick%3Dfunction(e)%7Bconsole.log(e)%7D%7D)()
Sebastian Speitel
  • 7,166
  • 2
  • 19
  • 38