简体   繁体   中英

How can I make a restrat button in JavaScript?

I have created a simple snake game using html and JavaScript. after the game over you need to press F5(refresh) button on keyboard to restart the game. I want to create a button called restart that upon being pressed refreshes the page . How can I do it?

Add this inside your Restart button to reload the page.

window.location.reload();

You should not refresh the page to Restart the Game. This feature should be implemented separately. Reset all parameters and rerun your game start code again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM