Very nice demo. I suspect Ian is particularly interested in safari so he will have to dig into that. My guess is that the BroadcastChannel is a fairly simple thing built on top of the underlying localstorage mechanism and I know that works in safari.
On Thu, Sep 7, 2017 at 1:45 AM, gmj <gm.juste...@gmail.com> wrote: > Thanks to Ian and Eric for an interesting question and direction. > Following Eric's lead I found (in all but Safari) > a built-in object BroadcastChannel which is what it claims to be. The > following 2 scripts illustrate its use in the > jhs context to perform what Ian requested. Perhaps there are 'polyfills' > for Safari? > > load each into jijx > open page http://localhost:65001/messager > open page http://localhost:65001/message > > enter text in textarea of messager page and click button > > look at message page > > browser debug stops in postMessage and bc.onmessage in messager and > message respectively > allow helpful insights > > NB. =================Sender============== > > Note'' > load into jijx > open page http://localhost:65001/messager > enter text in textarea and click button > > ~Projects/broadcastchannel/messager.ijs > Send message via Broadcast Channel object > https://developer.mozilla.org/en-US/docs/Web/API/Broadcast_Channel_API > ~addons/jhs/app/app1.ijs > ) > > coclass'messager' > coinsert'jhs' > > MESSAGE__=: 'Hello World 2' > > HBS=: 0 : 0 > jhh1'message - sender' > jhhr > 'b1'jhb'b 1' > 't1'jhtext MESSAGE__;20 > desc > ) > > desc=: 0 : 0 > <pre> > Send message via Broadcast Channel object > pressing b1 sends the text in 't1' > </pre> > ) > > NB. verb that responds to browser request for app1 page > NB. (tab title) jhrx (browser source to create the page) > jev_get=: 3 : 0 > 'messager'jhrx(getcss''),(getjs''),gethbs'' > ) > > ev_bc_onmessage=: 3 : 0 > newval=.getv'jdata' > jhrajax ('ev_bc_onmessage_',(;coname''),'_'),JASEP,newval > ) > > JS=: 0 : 0 > // Connection to a broadcast channel > var bc > ,jfn='ev_bc_onmessage_messager_ 0'; > > // Example of sending of a very simple message > function postMessage(msg){ > var o={}; > o.newval=msg; > o.jfn=jfn; > bc.postMessage(o); > } > > function ev_b1_click(){ > var msg = jbyid('t1').value; > postMessage(msg); > } > > function ev_body_load(){ > // Connect to a broadcast channel > bc = new BroadcastChannel('test_channel'); > } > > ) > > =================Receiver: load in jijx============== > Note'' > load into jijx > open page http://localhost:65001/message > > ~Projects/broadcastchannel/message.ijs > receive message via BroadcastChannel > https://developer.mozilla.org/en-US/docs/Web/API/Broadcast_Channel_API > ~addons/jhs/app/app1.ijs > ) > > coclass'message' > coinsert'jhs' > > HBS=: 0 : 0 > jhh1'message - receiver' > jhhr > 't1'jhtext'text field 1';20 > 't2'jhtext'text field 2';20 > desc > ) > > desc=: 0 : 0 > <pre> > receive message via BroadcastChannel > </pre> > ) > > NB. verb that responds to browser request for message page > NB. (tab title) jhrx (browser source to create the page) > jev_get=: 3 : 0 > 'receiver'jhrx(getcss''),(getjs''),gethbs'' > ) > > ev_bc_onmessage=: 3 : 0 > smoutput seebox NV > newval=.getv't1' > jhrajax ('ev_bc_onmessage_',(;coname''),'_'),JASEP,newval > ) > > ev_flip_click=:ev_bc_onmessage > > JS=: 0 : 0 > var bc; > > function ev_body_load(){ > // Connect to a broadcast channel > bc = new BroadcastChannel('test_channel'); > > // bc event handler > bc.onmessage = function(ev) { > console.log(ev); > jbyid('t1').value = ev.data.newval; > jbyid('t2').value = ''; > jscdo("flip"); > } > } > > // send t1 name/value pair to J > function ev_flip_click(){jdoajax(["t1"],'','',true);} > > // j response to msg > function ev_flip_click_ajax(ts){ > jbyid('t2').value = ts[1].toUpperCase(); > } > > ) > ============================================================ > ================ > On 09/06/2017 12:45 AM, Eric Iverson wrote: > > Ian, > > By resources, I meant google. The phrase that will get you started is > > 'javascript shared local storage'. A search of the JHS scripts will show > a > > few simple places where it is currently used. But there is no current use > > of the very interesting event triggers. > > > > On Tue, Sep 5, 2017 at 11:35 PM, Ian Clark <earthspo...@gmail.com> > wrote: > > > >> @Eric > >> > >> This could be useful. But my Javascript is so poor I can't really say > until > >> I've tried it. > >> > >>> One page setting shared memory can trigger an event in the javascript > of > >> the > >> other page. Is this of interest? > >> > >> Yes. When I first started thinking about my requirements, this was just > the > >> sort of generalized facility I'd hoped might exist. > >> I could then arrange for something to happen in the _message_ page as a > >> result of pressing Enter in _jijx_. Typically, force a reload of the > page. > >> Or just part of it. > >> > >> It would be nice too to be able to inspect the input line itself, e.g. > for > >> the target of "=:", to display it in _message_. > >> > >> Presently I'm experimenting with macOS apps with embedded JHS, and am > >> almost at the beta stage. But if shared memory delivers what it appears > to > >> hold out, I could shelve this approach in favor of using JHS "out of the > >> box" with any modern browser. My platform-migration problems would go > away. > >> > >>> …but the resources documneting its use are more that adequate. > >> I take it you're talking about online javascript resources, not JAL > >> resources. Can you give me a link pls? > >> > >> On Tue, Sep 5, 2017 at 10:43 PM, Eric Iverson <eric.b.iver...@gmail.com > > > >> wrote: > >> > >>> Ian (your JHS question), > >>> > >>> There is a facility in javascript in the browser called shared memory. > >> JHS > >>> uses this in a very limited way, but I have always wanted to revisit it > >> to > >>> see what else could be done. > >>> > >>> One page setting shared memory can trigger an event in the javascript > of > >>> the other page. Is this of interest? > >>> > >>> The existence of javascript shared memory has kept a low profile, but > the > >>> resources documneting its use are more that adequate. > >>> > >>> On Mon, Sep 4, 2017 at 10:20 PM, Ian Clark <earthspo...@gmail.com> > >> wrote: > >>>> In case that's not clear enough, here's an ultra-simple example, > >> stripped > >>>> of all the clutter. > >>>> > >>>> Here's the content of my script: '~user/message.ijs' ... > >>>> ——————————————————————————— > >>>> coclass 'message' > >>>> coinsert 'jhs' > >>>> > >>>> MESSAGE__=: 'Hello World' > >>>> > >>>> MYTEMPLATE=: 0 : 0 > >>>> HTTP/1.1 200 OK > >>>> Content-Type: text/html; charset=utf-8 > >>>> Connection: close > >>>> > >>>> <pre> > >>>> PAGECONTENT > >>>> </pre> > >>>> ) > >>>> > >>>> jev_get=: 3 : 0 > >>>> hrtemplate=: MYTEMPLATE rplc 'PAGECONTENT' ; MESSAGE__ > >>>> 'message' jhr '' > >>>> ) > >>>> ——————————————————————————— > >>>> > >>>> Load it and browse the URL: http://localhost:65001/message > >>>> > >>>> You see a mostly empty window (call it the message window) displaying: > >>>> > >>>> Hello World > >>>> > >>>> > >>>> Now I want to turn to the jijx window (http://localhost:65001/jijx) > >> and > >>>> enter > >>>> > >>>> MESSAGE__=: 'Hello New World' > >>>> refresh'' > >>>> > >>>> without having to touch the message window. > >>>> How do I write the verb: refresh ? > >>>> > >>>> It goes without saying that in practice I want to display something > >> more > >>>> elaborate than the contents of a single noun residing in the base > >> locale. > >>>> But the principle will be the same. > >>>> > >>>> > >>>> On Tue, Sep 5, 2017 at 2:59 AM, Ian Clark <earthspo...@gmail.com> > >> wrote: > >>>>> Suppose I am a JHS coder, working with the J session (the jijx page), > >>> and > >>>>> have written an app called "message" (say). This generates a page of > >>> data > >>>>> in response to the URL: > >>>>> > >>>>> http://localhost:65001/message > >>>>> > >>>>> which I choose to display in a separate browser window. Let's call it > >>> the > >>>>> message window. > >>>>> > >>>>> If I execute some phrase in jijx which changes the content of the > >>> message > >>>>> window, then in the normal course of things I would need to manually > >>>> reload > >>>>> the page in order to see the altered data. For example (in Safari) by > >>>>> activating the message window and clicking the symbol: "Reload this > >>>> page". > >>>>> How can I write a verb (to be executed in jijx) which refreshes the > >>>>> message window without having to do that? > >>>>> > >>>>> > >>>> ------------------------------------------------------------ > ---------- > >>>> For information about J forums see http://www.jsoftware.com/ > forums.htm > >>>> > >>> ---------------------------------------------------------------------- > >>> For information about J forums see http://www.jsoftware.com/forums.htm > >>> > >> ---------------------------------------------------------------------- > >> For information about J forums see http://www.jsoftware.com/forums.htm > >> > > ---------------------------------------------------------------------- > > For information about J forums see http://www.jsoftware.com/forums.htm > > > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm