You could pause the game when the cursor leaves the window of your game, but if you clicked outside the game would need input from the html page in your case.
Also worth mentioning, if the window (or tab) is not in focus, the game automatically pauses.