js.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>Embedded Javascript</title>
  5. <!-- Copyright Embedthis Software. All Rights Reserved. -->
  6. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  7. <meta charset="utf-8" />
  8. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
  9. <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
  10. <meta name="description" content="Simple, fast, secure embedded web server" />
  11. <link href='https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,700|Open+Sans:300italic,400,300,700'
  12. rel='stylesheet' type='text/css'>
  13. <link href='https://fonts.googleapis.com/css?family=Julius+Sans+One' rel='stylesheet' type='text/css'>
  14. <link href="../images/favicon.ico" rel="shortcut icon" />
  15. <link href="../lib/semantic-ui/semantic.min.css" rel="stylesheet" type="text/css" />
  16. <link href="../css/all.min.css" rel="stylesheet" type="text/css" />
  17. <link href="../css/api.min.css" rel="stylesheet" type="text/css" />
  18. </head>
  19. <body class="show-sidebar">
  20. <div class="sidebar">
  21. <div class="ui large left vertical inverted labeled menu">
  22. <div class="item">
  23. <a href="../" class="logo">GoAhead Docs</a>
  24. </div>
  25. <div class="item">
  26. <a href="../">
  27. <b>General</b>
  28. </a>
  29. <div class="menu">
  30. <a class="item" href="../">GoAhead Overview</a>
  31. <a class="item" href="../users/features.html">GoAhead Features</a>
  32. <a class="item" href="https://embedthis.com/goahead/download.html">Download</a>
  33. <a class="item" href="../licensing/">Licensing</a>
  34. </div>
  35. </div>
  36. <div class="item">
  37. <a href="../start/">
  38. <b>Getting Started</b>
  39. </a>
  40. <div class="menu">
  41. <a class="item" href="../start/quick.html">Quick Start</a>
  42. <a class="item" href="../start/installing.html">Installing GoAhead</a>
  43. <a class="item" href="../start/running.html">Running GoAhead</a>
  44. <a class="item" href="../start/releaseNotes.html">Release Notes</a>
  45. <a class="item" href="../start/faq.html">GoAhead FAQ</a>
  46. <a class="item" href="../start/source.html">Building from Source</a>
  47. </div>
  48. </div>
  49. <div class="item">
  50. <a href="../users/"><b>User's Guide</b></a>
  51. <div class="menu">
  52. <a class="item" href="../users/ports.html">Ports and Binding</a>
  53. <a class="item" href="../users/routing.html">Routing Requests</a>
  54. <a class="item" href="../users/handlers.html">Request Handlers</a>
  55. <a class="item" href="../users/js.html">Embedded Javascript</a>
  56. <a class="item" href="../users/jst.html">Javascript Templates</a>
  57. <a class="item" href="../users/goactions.html">GoActions</a>
  58. <a class="item" href="../users/cgi.html">CGI Programs</a>
  59. <a class="item" href="../users/authentication.html">User Authentication</a>
  60. <a class="item" href="../users/logFiles.html">Log Files</a>
  61. <a class="item" href="../users/ssl.html">Secure Sockets (SSL)</a>
  62. <a class="item" href="../users/security.html">Security Considerations</a>
  63. <a class="item" href="../users/man.html">Man Pages</a>
  64. </div>
  65. </div>
  66. <div class="item">
  67. <a href="../developers/">Developer's Guide</a>
  68. <div class="menu">
  69. <a class="item" href="../developers/embedding.html">Embedding GoAhead</a>
  70. <a class="item" href="../developers/handlers.html">Creating GoAhead Handlers</a>
  71. <a class="item" href="../developers/authstore.html">Creating Password Verifiers</a>
  72. <a class="item" href="../developers/migrating.html">Migrating to GoAhead 3</a>
  73. <a class="item" href="../developers/rom.html">Serving Pages from ROM</a>
  74. </div>
  75. </div>
  76. <div class="item">
  77. <a href="../ref/">Reference Guide</a>
  78. <div class="menu">
  79. <a class="item" href="../ref/compatibility.html">Compatibility</a>
  80. <a class="item" href="../ref/native.html">API Library</a>
  81. <a class="item" href="../ref/architecture.html">GoAhead Architecture</a>
  82. <a class="item" href="../standards/http.html">HTTP References</a>
  83. </div>
  84. </div>
  85. <div class="item">
  86. <a href="../developers/project.html">Project Resources</a>
  87. <div class="menu">
  88. <a class="item" href="http://goo.gl/IGbiio">Official GoAhead News</a>
  89. <a class="item" href="https://embedthis.com/goahead/">GoAhead Web Site</a>
  90. <a class="item" href="https://github.com/embedthis/goahead">Source Code Repository</a>
  91. <a class="item" href="https://github.com/embedthis/goahead/issues/99">GoAhead Security Alerts</a>
  92. <a class="item" href="https://github.com/embedthis/goahead/issues">Project Issue Database</a>
  93. <a class="item" href="https://github.com/embedthis/goahead/releases">Change Log</a>
  94. <a class="item" href="https://github.com/embedthis/goahead/milestones">Roadmap</a>
  95. <a class="item" href="https://embedthis.com/developers/contributors.html">Contributors Agreement</a>
  96. </div>
  97. </div>
  98. <div class="item">
  99. <b>Links</b>
  100. <div class="menu">
  101. <a class="item" href="https://embedthis.com/">Embedthis Web Site</a>
  102. <a class="item" href="https://embedthis.com/blog/">Embedthis Blog</a>
  103. <a class="item" href="http://twitter.com/embedthat">Twitter</a>
  104. </div>
  105. </div>
  106. </div>
  107. </div>
  108. <div class="ui inverted masthead">
  109. <div class="ui fixed inverted menu">
  110. <div class="ui sidebar-launch button">
  111. <i class="icon list layout"></i>
  112. </div>
  113. <div class="right menu">
  114. <a class="item" href="https://embedthis.com/">Embedthis</a>
  115. <a class="item" href="https://embedthis.com/goahead/">GoAhead Site</a>
  116. <span class="desktop-only">
  117. <a class="item" href="http://goo.gl/9bL9rM">GoAhead News</a>
  118. <a class="item" href="https://github.com/embedthis/goahead">Repository</a>
  119. <a class="item" href="https://embedthis.com/blog/">Blog</a>
  120. <a class="item" href="https://twitter.com/embedthat">Twitter</a>
  121. </span>
  122. </div>
  123. </div>
  124. <div class="ui breadcrumb">
  125. <a class="section" href="../">Home</a>
  126. <div class="divider">/</div>
  127. <a class="section" href="../users/">
  128. User's Guide
  129. </a>
  130. <div class="divider">/</div>
  131. <a class="active section" href="js.html">Embedded Javascript</a>
  132. </div>
  133. <iframe class="version desktop-only" src="../version.html"></iframe>
  134. </div>
  135. <div class="content">
  136. <h1>Embedded Javascript</h1>
  137. <p>GoAhead provides an embedded version of Javascript for use in JST pages. As the full Javascript 6
  138. specification is quite a large language, GoAhead's implements a small subset suitable for embedded use.
  139. GoAhead Javascript&trade; is a strict subset of Javascript and implements the essential elements of the language.
  140. It also provides the engine for JST pages to enable the easy creation of dynamic web pages.</p>
  141. <p>A standalone product, <a href="https://embedthis.com/ejscript/">Embedthis Ejscript&trade;</a> more
  142. fully supports the latest Javascript 6 specification and when used
  143. with the <a href="https://embedthis.com/appweb/">Appweb</a> embedded web server
  144. is an alternative to GoAhead if you have sufficient memory available.</p>
  145. <p>When GoAhead Javascript is used inside a JST web page, it consists of a script within JST delimiters.
  146. The basic format is:</p>
  147. <pre class="ui code segment">&lt;% function(arguments, ...); %&gt;</pre>
  148. <p>Javascript functions are created by the jsSetGlobalFunction. When the function is evaluated, the
  149. corresponding C procedure that implements the Javascript function is called.</p>
  150. <p>GoAhead Javascript implements the following Javascript elements:</p>
  151. <ul>
  152. <li>Case sensitivity</li>
  153. <li>White space</li>
  154. <li>Semicolons</li>
  155. <li>Comments</li>
  156. <li>Identifiers</li>
  157. <li>Data types including numbers, booleans, and strings with backslash characters</li>
  158. <li>Full expressions</li>
  159. <li>If/else, for, return</li>
  160. <li>Global function calls</li>
  161. </ul>
  162. <p>The following language elements are not implemented:</p>
  163. <ul>
  164. <li>Arrays</li>
  165. <li>Objects</li>
  166. <li>Labeled statements</li>
  167. <li>Control flow statements including: break, case, continue, default, do/while, export, for/in, function,
  168. import,switch, var, while, and with</li>
  169. <li>Regular expressions</li>
  170. </ul>
  171. <p>Javascript scripts can span multiple lines by using "\" as the last character on the preceding line. When
  172. used in JST pages, function arguments can contain any query variable defined in either the URL query string or
  173. the standard variable set. URL query strings are automatically decoded, and Javascript variables are defined to
  174. the decoded query value. For example, to parse the name and address encoded as a query string in a URL, use the
  175. following code:</p>
  176. <pre class="ui code segment">http://localhost/mypage?name=smith&amp;age=35</pre>
  177. <pre class="ui code segment">
  178. int myAspProcedure(Webs wp, int argc, char **argv) {
  179. char *name = websGetVar(wp, "name", "undefined");
  180. char *age = websGetVar(wp, "age", "undefined");
  181. websWrite(wp, "Name %s, Age %s", name, age);
  182. }
  183. </pre>
  184. <p>Javascript procedures are registered by using the <a
  185. href="../ref/api/goahead.html#group___webs_1ga4db3f71301ed08e4f8d3c466d3632ea1">websDefineJst</a> API.
  186. This publishes a C procedure as a Javascript global function. For example:</p>
  187. <pre class="ui code segment">
  188. extern int outputMyTable(int ejid, Webs wp, int argc, char **argv);
  189. websDefineJst("outputTable", outputMyTable);
  190. </pre>
  191. <p>The websDefineJst call publishes the Javascript command "outputTable" and links it to the
  192. outputMyTable C procedure. When an JST page is requested by the user's browser, any JST
  193. Javascript which uses the outputTable command will cause the outputMyTable to be called with
  194. the relevant arguments.
  195. </div>
  196. <div class="terms ui basic center aligned segment">
  197. <p>&copy; Embedthis Software, 2003-2015. All rights reserved.</p>
  198. </div>
  199. <script src="../lib/jquery/jquery.min.js"></script>
  200. <script src="../lib/semantic-ui/semantic.min.js"></script>
  201. <script src="../scripts/sidebar.min.js"></script>
  202. </body>
  203. </html>