I have a solution, although if you want the counter to be persistent over refreshes (let me know and I will edit my answer) you will have to modify it. My solution is to add a variable that increases by one every time the button is click, and then check to see if it has exceeded a value:
let count = 0
const eventListener = () => ((count += 1) < 10/*your max # of clicks*/) ? alert('max # of clicks')/*whatever you want to do*/ : window.open('www.google.co.uk')
or, if you are using the HTML onclick
property, and want it to all be on one line:
<button onclick="(((window.count || window.count = 0) += 1) < 10/*your max # of clicks*/) ? alert('max # of clicks')/*whatever you want to do*/ : window.open('www.google.co.uk')">Open google</button>
This javascript sets a count variable to 0 then, after each button click, it increases the counter and checks to see if it is greater than your max number of clicks at the same time. After that it does whatever you want it to do depending on if it (the counter) is larger than the max number or not.