Reference:GeoGebra Apps Embedding

From GeoGebra Manual
Revision as of 10:51, 22 February 2017 by Zbynek (talk | contribs) (CDN url of deployggb.js)
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>

In case you are using the Math Apps Bundle, please use

    <script src="GeoGebra/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 from tube as a parameters.

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);

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.

Add also: (if the applets contain 3D view)

    applet1.setHTML5Codebase('https://app.geogebra.org/5.0/web3d/');
    applet2.setHTML5Codebase('https://app.geogebra.org/5.0/web3d/');

In case you are using the Math Apps Bundle, please use

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

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>

At the end of the script section the applets are injected to this divs using the inject function:

    window.onload = function() {
        applet1.inject('applet_container1', 'preferHTML5');
        applet2.inject('applet_container2', 'preferHTML5');
        applet3.inject('applet_container3', 'preferHTML5');
    }

The parameters of the method inject() are:

Parameter Description
containerID A string with the id of the HTML object that will be the parent of the applet.
appletType This can be one of the following keywords:
preferHTML5 (default)
use HTML5 whenever possible (on tablets and with modern browsers), only fall back on Java otherwise (e.g. with Internet Explorer 8)
html5
force HTML5 to be used -- prevents Java from loading, old browser users won't be able to use the applet

Other values are deprecated.

Examples

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

© 2024 International GeoGebra Institute