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.
If you came to this page after seeing the embedFrame deprecation warning, you should not be using that method unless your game spans multiple pages. If your app utilizes multiple pages and they all need to access the Kongregate API, then it is fine to use the shell.
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
// 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.
Updated over 3 years ago