Reference:GeoGebra Apps Embedding

From GeoGebra Manual
Revision as of 22:02, 25 April 2017 by Zbynek (talk | contribs) (removed applet type)
Jump to: navigation, search

This article describes how to embed GeoGebra Math Apps into your website or offline HTML materials using Javascript.

Note: Alternative solution is to embed materials from GeoGebra Materials Platform in your website as an iframe. See Reference:Material_Embedding_(Iframe) for details.

Location of Math Apps

You can use Math Apps from our CDN (app.geogebra.org) or you can download them as Math Apps Bundle that you can host on your own server or use offline.

Download Math Apps Bundle

Embed using Javascript

This method is recommended when multiple HTML5 applets are embedded in one page, or if you need to use the JavaScript API. In this case they can share one instance of the GeoGebra codebase and load faster. Here is an example web page that shows how to embed applets: Example page.

You need to include the following three parts in your HTML file:

1 The javascript library deployggb.js needs to be included with this tag:

    <script src="https://cdn.geogebra.org/apps/deployggb.js"></script>

2 For each applet a javaScript object of the type GGBApplet needs to be created. It takes at least the material ID or URL as a parameter.

Here is the according code from the example page that creates 2 applets:

    var applet1 = new GGBApplet({material_id: "17499", borderColor:"#55FF00"}, true);
    var applet2 = new GGBApplet({filename: "../ggb/sine-curves.ggb","showtoolbar":true}, true);
   window.addEventListener("load", function() {
        applet1.inject('applet_container1');
        applet2.inject('applet_container2');
    });

The above example shows how to load a file using the filename or the id of the material on GeoGebra Materials Platform. For offline use you will need to specify the file using a base64 encoded string (press Ctrl+Shift+B to export ggbBase64 string to clipboard).

When used with the id parameter, the applet will be created using the dimensions (width and height) and the applet parameters defined in the material settings on GeoGebra Materials Platform. Optionally you can override these settings by passing them in the parameters. See Reference:Applet_Parameters for a list of applet parameters.

In the example the parameter 'showMenuBar:true' overrides the material setting from tube to show the menu bar for applet3.

The parameter of the method inject() is a string with the id of the HTML object that will be the parent of the applet.

3 Finally, you need to determine where the applet should appear in the document and inject the applet. In our example file we create a div as parent for each applet, like this:

    <div id="applet_container1"></div>
Note: In case you are using the Math Apps Bundle, please change the first script tag to
    <script src="GeoGebra/deployggb.js"></script>

and include the following two lines below the definition of applet2

    applet1.setHTML5Codebase('GeoGebra/HTML5/5.0/web3d/');
    applet2.setHTML5Codebase('GeoGebra/HTML5/5.0/web3d/');

Examples

es:Referencia:Applet Embebido fr:Référence:Appliquettes_imbriquées it:Riferimenti:Incorporare_Applet

© 2024 International GeoGebra Institute