Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
blocks:app-note:basic-interaction-from-a-custom-web-page [2021-05-01 15:26]
admin clarification
blocks:app-note:basic-interaction-from-a-custom-web-page [2021-08-09 06:16] (current)
mattias [Custom Web Page]
Line 16: Line 16:
   - Open a second browser window to the same address as the editor window, but replace /edit/xxx with /public/html/WebTask.html to open the custom web page (see below).   - Open a second browser window to the same address as the editor window, but replace /edit/xxx with /public/html/WebTask.html to open the custom web page (see below).
   - Click the //One// button.   - Click the //One// button.
 +
 +{{ :blocks:app-note:custom-web-page:customwebpage.png?nolink |}}
  
 When you click the button, the "Started" message will be logged on the Task page in the Editor. When you click the button, the "Started" message will be logged on the Task page in the Editor.
Line 63: Line 65:
 This //startTask// function is defined in the //<script>// section of the code. The function makes a POST request to a URL on the Blocks server, passing it an object named taskPar, specifying the name of the task to run. This //startTask// function is defined in the //<script>// section of the code. The function makes a POST request to a URL on the Blocks server, passing it an object named taskPar, specifying the name of the task to run.
  
-:!: The URL specified in the //fetch// request omits the protocol and server name. That's OK since the fetch request is calling back to same server as the web page is served from the. If your web page isn't hosted on your Blocks server, you need to prefix the URL with the protocol and host name (or IP address), like this:+:!: The URL specified in the //fetch// request omits the protocol and server name. That's OK since the fetch request is calling back to same server as the web page is served from. If your web page isn't hosted on your Blocks server, you need to prefix the URL with the protocol and host name (or IP address), like this:
  
 <code> <code>
Line 72: Line 74:
 ==== User Script ==== ==== User Script ====
  
-Code also exists on the server side (in the files script/user/WebTask.ts and WebTask.js) to receive and act upon the request. The best way to view this code is by using a code editor. See this article for setting up a code editor for use with Blocks. But if you just want to take a look, any text editor will do.+Code also exists on the server side (in the files script/user/WebTask.ts and WebTask.js) to receive and act upon the request. The best way to view this code is by using a code editor. See [[blocks:drivers:tools|this article]] for setting up a code editor for use with Blocks. But if you just want to take a look, any text editor will do.
  
 Much of the script file is comments, with the most interesting part being the //start// function. As you can see, the name of this function corresponds to the last word in the URL called from the custom web page. Likewise, the name of the user script (WebTask) corresponds to the second last part of the URL (see above). Here's the start function that does the heavy lifting in this script: Much of the script file is comments, with the most interesting part being the //start// function. As you can see, the name of this function corresponds to the last word in the URL called from the custom web page. Likewise, the name of the user script (WebTask) corresponds to the second last part of the URL (see above). Here's the start function that does the heavy lifting in this script:
Line 106: Line 108:
 ==== Next Step ==== ==== Next Step ====
  
-While the above example may be perfectly adequate for what you want to accomplish, the application note titled "Advanced Interaction from a Custom Web Page" provides more options, including real-time bidirectional communication between Blocks and a custom web page.+While the above example may be perfectly adequate for what you want to accomplish, the application note titled "[[blocks:app-note:interacting-from-a-custom-web-page|Advanced Interaction from a Custom Web Page]]" provides more options, including real-time bidirectional communication between Blocks and a custom web page.