Integrate Kongregate’s JavaScript API in HTML5 Game to Submit High Score

Though Kongregate’s API can be directly initialized in the main game’s HTML, the better way is to always create a Kongregate’s Shell which is nothing but another HTML file which you refer for running the game in stead of your default game’s HTML file. The Shell file in turn embeds your game’s default HTML file using an iFrame. Code for Shell HTML can be used from the code snippet below

You can change index.html to refer to your game’s HTML file name. Also, you need to ensure the width and height is properly set for your game for “contentdiv”. Define your localStorage as following in a separate js file (for ex storage.js)

Now in the game’s HTML add code as highlighted below

High scores should be submitted twice. Once at the completion of game’s stage, whenever high score is achieved. And then second time whenever game is initially[…]