JavaScript
Questions answered by this recipe
- How can I embed static JavaScript into a wiki page?
(For information about using wiki markup to create or edit JavaScript, see JavaScript-Editable.)
Description
Getting JavaScript into a wiki page is easily done by creating a custom markup for it. For example, weather.com provides me with the following JavaScript code for displaying weather information on a webpage:
<script src='http://voap.weather.com/weather/oap/75025?template=LAWNH&par=null&unit=0&key=77351fbfbbfc1099f80fa310e5f58b52'></script>
So, to create a custom (:weather:)
markup that will output this JavaScript code, define a custom markup in local/config.php or a group customization as:
Markup('weather', 'directives', '/\\(:weather:\\)/', Keep("<script src='http://voap.weather.com/weather/oap/75025?template=LAWNH&par=null&unit=0&key=77351fbfbbfc1099f80fa310e5f58b52'></script>"));
This results in:
Injecting JavaScript
You can inject JavaScript either in the skin template, or in the $HTMLHeaderFmt
or $HTMLFooterFmt
arrays.
Examples using the arrays:
- see
scripts/stdconfig.php
injectingpub/pmwiki-utils.js
. $HTMLHeaderFmt['specific- javascript'] = '<script> // the JavaScript code to be injected </script>';
See Also
Contributors
- Pm
Comments
See discussion at JavaScript-Talk?
User notes? : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.