No web server
This example illustrates some of the new web features in MonkeyTerm v2+.
For reference you might want to take a peek at the MOM.
This example explains how you can communicate with the browser window with out having the MT webserver runnning.
The basic idea is to give the session and the application objects to the browser. This way you can access the
MT class hierachy from JavaScript. Excellent eh?
We make the on load event force the browserwindow to load the appropriate page using file://. This is done in the "OnLoad" Event.
<%
session.browser.width=6200
session.browser.visible=true
session.updatelayout
Session.browser.locationurl="file://" & session.expandpath("%sessionpath%/NoWebServer.htm")
%>
This is how this help document is loaded. And, as you can see, it works. Press F10 to find this events in the FMT.
When you click this link it will execute the following command: "2s3n10e".
This is done from javascript.
In order to do that we have to give "the objects" to the browser. So first we need to have an
interface that MT can give the objects through. We do that by making including this script on the html page
<script>
var session;
var application;
function giveObjects(oSes,oApp) {
session=oSes;
application=oApp;
}
document.giveObjects=giveObjects;
function firecmd(sCmd) {
session.evaluatecommand(sCmd);
}
</script>
Now we can in the MT OnDocumentComplete event give the objects to the browser.
We drop errorhandling in case the displayed document doesn't support our giveObjects interface.
event name: OnDocumentComplete
event type: OnDocumentComplete
Command:
<%
on error resume next
web.doc.giveObjects session,application
on error goto 0
%>
Enabled: yes
Press F10 to find the event in the FMT.
You can access the document object of the browser through web.doc. This can be used for all kinds of fancy
stuff.
- Blink browser background when friend enters
- Show HP/Mana in a nice graphical way.
- write your score sheet to the browser window
- ...
Or like in this cool example change the text of a <span> element whenever a timer event fires in the session.
This clock is updated by the event "TestTimer" in monkey term: "A clock"
The html code for the element is
<span id="Tester">Monkey</span>
The updating event "TestTimer" is constructed like this:
event name: TestTimer
event type: Timer
Command:
<%
set tester=web.doc.getElementById("Tester")
if not tester is nothing then tester.innerText=now
%>
Interval: 1
FireOnce: no
Enabled: yes