Join us in Outworldz at www.outworldz.com:9000 or follow us:

Search dozens of selected web sites for OpenSim and LSL script

New! Script Meta-Search will search thousands of scripts here and at other sites for LSL or Opensim scripts.
Loading

Want to add a script or a project? Upload it and a half million people will see it and your name here this year.

Home   Show All
Category: Contributor: Creator
Viewer 2 Selfserved_HTML_and_JavaScript  

Selfserved_HTML_and_JavaScript

Example #1 using script src= and .inner...

Category: Viewer 2
By : Becky Pippen
Created: 2010-09-02 Edited: 2010-09-02
Worlds: Second Life

the Zip file

Download all files for Selfserved_HTML_and_JavaScript
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. Selfserved_HTML_and_JavaScript_1.lsl
Get file # 2. Selfserved_HTML_and_JavaScript_2.lsl
1 integer face = 4;
2 string myURL;
3
4 // This can be up to 2KBytes after %-hex-escaping:
5 string servedPage = "
6 function checklength(i){if(i<10) {i='0'+i;} return i;}
7 function clock(){
8 var now = new Date();
9 var hours = checklength(now.getHours());
10 var minutes = checklength(now.getMinutes());
11 var seconds = checklength(now.getSeconds());
12 var format = 1; //0=24 hour format, 1=12 hour format
13 var time;
14 if(format == 1) {
15 if(hours >= 12) {
16 if(hours ==12 ) { hours = 12;
17 } else { hours = hours-12; }
18 time=hours+':'+minutes+':'+seconds+' PM';
19 } else if(hours < 12) {
20 if(hours ==0) {hours=12;}
21 time=hours+':'+minutes+':'+seconds+' AM';
22 }
23 }
24 if(format == 0) {time= hours+':'+minutes+':'+seconds;}
25 document.getElementById('clock').innerHTML=time;
26 setTimeout('clock();', 500);
27 } "; // yes, that's one long string.
28
29 displayPage()
30 {
31 string dataURI = "data:text/html,<script src='" +
32 myURL + "'></script>" +
33 "<div id='clock'><script>clock();</script></div>";
34 llSetPrimMediaParams(face, [PRIM_MEDIA_CURRENT_URL, dataURI]);
35 }
36
37 default
38 {
40 {
42 }
43
44 http_request(key id, string method, string body)
45 {
46 if(method == URL_REQUEST_GRANTED) {
47 myURL = body;
48 displayPage();
49 } else if(method == "GET") {
50 llHTTPResponse(id, 200, servedPage);
51 }
52 }
53 }

Selfserved_HTML_and_JavaScript

Example #2 using body onload= (lag graph example)

* Like the previous example, this is another variation of how to structure a data URI to serve as a springboard for arbitrarily large pages. In this example, the data URI first uses a script src= tag to read a file of external JavaScript functions in the head element, and then the onload= attribute in body triggers a call to one of the functions which executes a loop creating a bunch of hr elements that form the bar chart. The size of HTML generated by the JavaScript can be as large as the browser permits.
* In this example, jsURL is set to the script's own HTTP-in URL so that the example can be self-contained, but you can point jsURL to an external URL as well. If served by an external server, the JavaScript read in can be as large as the browser permits.
* head can be omitted in the data URI surrounding the script src= tag.

Category: Viewer 2
By : Becky Pippen
Created: 2010-09-02 Edited: 2010-09-02
Worlds: Second Life

1 integer face = 4;
2 string jsURL; // where to fetch external JavaScript
3 list numbers;
4 integer numSamples = 50;
5
6 // This is self-served in this example, but can be
7 // moved to an external server:
8 //
9 string externalJavascript()
10 {
11 return
12 "function bar(widthPct,heightPix) {" +
13 " document.writeln(\"<hr style='padding:0;margin:0;" +
14 " margin-top:-1px;text-align:left;align:left;border=0;" +
15 " width:\"+widthPct+\"%;height:\"+heightPix+\"px;" +
16 " background-color:#c22;color:#c22;'>\");}" +
17 " function graphBars(arr){for(var i=0;i<arr.length;++i)" +
18 " {bar(arr[i],18);}}";
19 }
20
21 default
22 {
24 {
25 llClearPrimMedia(face);
27 integer i = numSamples;
28 while(--i >= 0) {
29 numbers += 0;
30 }
31 }
32
33 timer()
34 {
35 numbers = llList2List(numbers, 1, -1) + [(integer)(6.0 * (45.0 - llGetRegionFPS()))];
36
37 // The dataURI loads external JavaScript functions and calls one with parameters:
38
39 string dataURI = "data:text/html," +
40 "<head><script src='" + jsURL + "'></script></head>" +
41 "<body onload=\"graphBars([" + llList2CSV(numbers) + "]);\"></body>";
42
43 llSetPrimMediaParams(face, [PRIM_MEDIA_CURRENT_URL, dataURI, PRIM_MEDIA_AUTO_PLAY, TRUE]);
44 }
45
46 http_request(key id, string method, string body)
47 {
48 if(method == URL_REQUEST_GRANTED) {
49 jsURL = body; // self-serve the JavaScript
50 llSetTimerEvent(1.0);
51 } else if(method == "GET") {
52 llHTTPResponse(id, 200, externalJavascript());
53 }
54 }
55 }

Back to the Best Free Tools in Second Life and OpenSim.