I'm working on modernizing Rosetta Code's infrastructure. Starting with communications. Please accept this time-limited open invite to RC's Slack.. --Michael Mol (talk) 20:59, 30 May 2020 (UTC)

User talk:La Longue Carabine

From Rosetta Code

Comments and Discussion[edit]

Whatever.

To Use Spidermonkey Examples in HTML Documents[edit]

My JavaScript Spidermonkey examples (those which do not use readline() or read from files, anyway) 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 hash-bang line,

4. Comment out the call to main(),

5. Load into your browser and enjoy!

<html>
<head>
<script>
var outElmId = 'output';
var printBuf = '';
function putstr() {
    var pad = arguments.length > 1 ? ' ' : ''
    for (var i = 0; i < arguments.length; i++) {
        printBuf += arguments[i] + pad;
    }
}

function print() {
    var pad = arguments.length > 1 ? ' ' : ''
    for (var i = 0; i < arguments.length; i++) {
        putstr(arguments[i] + pad);
    }
    var d = document.createElement('div');
    d.innerHTML = printBuf;
    document.getElementById(outElmId).appendChild(d);
    printBuf = '';
}

// Put my code here, but remove the hash-bang and call to main
// #!/usr/bin/env js

// ...

//main()

</script>
</head>
<body onload="main()">
<pre id="output"></pre>
</body>
</html>