Differences

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

Link to this comparison view

Next revision
Previous revision
blocks:app-note:intra-browser-communication [2020-08-08 09:18]
admin created
blocks:app-note:intra-browser-communication [2023-08-01 21:06] (current)
admin [Installation]
Line 10: Line 10:
 ===== Installation ===== ===== Installation =====
  
-You need a computer running Blocks server software and a web browser to run this application note. Here's the {{ :blocks:app-note:intra-browser-communication:intrabrowsercomms.zip |Blocks root}} containing this application note. See the [[https://int.pixilab.se/docs/blocks/app-note/start|general setup]] article for details on how to download and install the root on your blocks server. +You need a computer running Blocks server software and a web browser to run this application note. Here's the {{ :blocks:app-note:intra-browser-communication:intrabrowsercomms.zip |Blocks root}} containing this application note. See the [[blocks:app-note:start|general setup]] article for details on how to download and install the root on your blocks server. 
  
 ===== Running the Example ===== ===== Running the Example =====
Line 43: Line 43:
 Available message types and their data are: Available message types and their data are:
  
- * **set-location** location ID. +  * **set-location** location ID. 
- * **set-tags** comma-separated list of tags to set. +  * **set-tags** comma-separated list of tags to set. 
- * **goto-page* Block path to track down in the currently loaded root block (slash separated). +  * **goto-block** Block path to track down inside the currently loaded root block (slash-separated). 
- * **go-back** Navigate back to the previous block path.+  * **go-back** Navigate back to the previous block path
 +  * ** action** Indicate action inside iframe that should keep any enclosing attractor at bay.
  
-Here the Visitor Spot is inside an iframe, so it can be targeted as shown in the sendMsg function above. If the Blocks Spot is the outer window, with your custom content shown using a Web Block, use //window.parent// to access the parent window instead. More information on how to send messages between window objects can be found here:+Here the Visitor Spot is inside an iframe, so it can be targeted as shown in the sendMsg function above. If the Blocks Spot is the outer window, with your custom content shown using a Web Block, use //window.parent// to access the parent window instead.  
 + 
 +Here are some more examples on how to call those functions: 
 + 
 +<code> 
 +/* Keep Blocks Attractor at bay when user interacts with content. 
 +  Block can not detect user interaction inside a Web Block without 
 +  such notifications. 
 +*/ 
 +parent.postMessage({type: 'action'}, '*'); 
 + 
 +/* Navigate to specified child block. Always uses absolute block path starting 
 +   from he outermost block playing on the spot. If you're using Reference Block 
 +   to bring in the content making the outgoing call, remember that all paths 
 +   must be specified from the top of the outermost (root) block, not relative 
 +   to the referenced block. 
 +*/ 
 +parent.postMessage({type: 'goto-block', data: "/path/to/block"}, '*'); 
 + 
 +/* Go back to previous block path. 
 +*/ 
 +parent.postMessage({type: 'go-back'}, '*'); 
 + 
 +/* Tell any Locator to locate Spot with Location ID 12. 
 +*/ 
 +parent.postMessage({type: 'set-location', data: 12}, '*'); 
 + 
 +/* Specify local tags of this Spot. Comma separate multiple tags. 
 +*/ 
 +parent.postMessage({type: 'set-tags', data: 12}, '*'); 
 +</code>  
 + 
 +More information on how to send messages between window objects can be found here:
  
 https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage
  
 Finally, if you want to send a message right away, as your enclosing web page is loaded, you must first wait for the iframe containing the Visitor Spot to load before you can send messages to it.  Finally, if you want to send a message right away, as your enclosing web page is loaded, you must first wait for the iframe containing the Visitor Spot to load before you can send messages to it.