Embedding Your Game Using the Kongregate Shell
embedFrame method of the kongregateAPI object to properly embed your game into a sub-frame. Your game can then act normally, while still always having access to the Kongregate API via
parent.kongregate. In order to use the shell, you must simply host it on your domain, and modify the
embedFrame call to point to the proper location on your server.
path:String- Path to load into the frame
elementID:String- The id of the element to insert the iframe into
Example: Embed a game iframe into the element named "contentdiv".
// Pass the user_id and game_auth_token parameters through for authentication. var params = "kongregate_user_id=" + kongregate.services.getUserId() + "&kongregate_game_auth_token=" + kongregate.services.getGameAuthToken(); // Embed the kongregate-game.php file into the element named "contentdiv" kongregateAPI.embedFrame("kongregate-game.php?" + params, "contentdiv");
Note that the shell will not work properly unless it is embedded into a Kongregate game page. In order to test, you should modify your game settings and set the Iframe URL to the location of the shell file on your server.
The contents of the example shell file can be found below. As you can see, it simply sets a placeholder
div element and calls the
embedFrame function once the API has been properly initialized. This ensures that the API is only loaded once, and that anything you do within your iframe is sandboxed properly so that the connection is not broken.