From MegaZine3
(Redirected from Javascript)
Jump to navigation Jump to search
{{#if: | }} {{#if: | }}{{#if: * javascript.swf | }}{{#if: * Links}}
Plugin: JavaScript
Name JavaScript
Since version


  • javascript.swf
Related plugins

The JavaScript plugin introduces a common interface for the engine and other plugins to communicate with JavaScript, should the engine run in a browser. It provides two interfaces, one for itself, so that other plugins can access it, and one other plugins can implement so they can add themselves to the list of JavaScript aware plugins. All registered plugins will be notified when the JavaScript plugin's setting "jsenabled" is set to true.

All plugins should use this way when offering JavaScript functionality, to allow a common behavior and centralized way of controlling the use of JavaScript.

The Javascript interface defined and made availalble with js/megazine.js only works if

  • the javascript plugin is activated (listed in the 'plugins' attribute), and
  • MegaZine3 runs on a server (a 'real' or a local one like XAMP). If you call a local file directly in a browser, the book might show up, but the Javascript API will not work!

Plugin interactions

The JavaScript plugin registers a protocol with the Links plugin, if loaded. The registered protocol is javascript: and can be used to run JavaScript code if the book is displayed using a browser. Example usage:

<element url="javascript:alert('test');"/>


== jsenabled =={{#if: Boolean |

  • Type: Boolean}}{{#if: |
  • Valid values: {{{valid}}}}}{{#if: true |
  • Default: true}}{{#if: |
  • Overrides: {{{overrides}}}}}{{#if: enablejs |
  • Aliases: enablejs}}{{#if: |
  • Version: {{{version}}}}}

This setting can be used to globally enable or disable JavaScript interaction of the book. As all plugins should use this plugin for registering and enabling JavaScript functionality, this will control the use of any JavaScript use at all, meaning if set to false it can be guaranteed (when using "nice" plugins) that there will indeed be no JavaScript interaction used.{{#if: |

  • See also: {{{see}}}}}


This plugin handles no attributes.


<book plugins="javascript,swfaddress,links">
            <img src="test.jpg" url="javascript:alert('Hello World!');"/>
        <!-- ... -->

Example showing the use of the Javascript API (functions defined in megazine.js):

    $('#megazine').before('<div id="header" style="display:inline; height:50px; width:100%">');
    $('#header').prepend('<p style="color:#ffffff;" id="pgnum"></p>');
    $('#pgnum').text('jQuery initialzied');
    MegaZine.onJSInit = function() {
      MegaZine.onPageChange = function(newPageNumber){$('#pgnum').text('page number: ' + newPageNumber.toString(10))};

First an HTML 'div' block with id 'header is inserted above the book, with one paragraph (id #pgnum) which will be updated when a page is turned. The JS API is availbale after the book is initialized. When everything is ready, the API is available and the function defined as handler for onJSInit will be called. Here the handler for onPageChange is defined, which will be called during a page turn. That function provides the new and old page number as their 2 parameters. The first parameter (new page) is used to update the text in the #pgnum paragraph. All available functions can be found in the js/megazine.js class.

MegaZine3 Plugin-related articles
Plugins Anchors · Background Sounds · Batchpages · Bookmarks · Console · ElementIDs · Gallery · Google Analytics · Help · JavaScript · Keyboard Navigation · Links · NavigationBar · Options · Overlays · Password · PDFLinks · Print · PrintPDF · SWFAddress· Search · Sidebar · Slideshow · Titles
Plugin Articles Writing a plugin · Writing a plugin II · Plugin development

{{#if: | |}}