User talk:La Longue Carabine: Difference between revisions

m
→‎Analyze and Discuss: Added instructions for putting Spidermonkey code on an HTML page.
No edit summary
m (→‎Analyze and Discuss: Added instructions for putting Spidermonkey code on an HTML page.)
Line 1:
==Analyze and Discuss==
Whatever.
 
 
== To Use Spidermonkey Examples in HTML Documents ==
 
Most of my examples implemented in Spidermonkey can be used on an HTML page as follows:
 
1. Create an HTML page like the one below,
 
2. Paste the Spidermonkey script into it,
 
3. Comment out the call to <code>main()</code>,
 
4. Load into your browser and enjoy!
 
<pre>
&lt;html&gt;
&lt;head&gt;
&lt;script&gt;
var outElmId = 'output';
var printBuf = '';
function putstr() {
for (var i = 0; i &lt; arguments.length; i++) {
printBuf += arguments[i];
if (arguments.length &gt; 1) printBuf += ' ';
}
}
 
function print() {
for (var i = 0; i &lt; arguments.length; i++) {
putstr(arguments[i]);
if (arguments[i].length &gt; 1) putstr(' ');
}
var d = document.createElement('div');
d.innerHTML = printBuf;
document.getElementById(outElmId).appendChild(d);
printBuf = '';
}
 
// Put my code here, but remove the call to main
// that is usually the last line of the script.
//main()
 
&lt;/script&gt;
&lt;/head&gt;
&lt;body onload="main()"&gt;
&lt;pre id="output"&gt;&lt;/pre&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>