[Jprogramming] How can I auto-refresh a JHS app page?
Raul Miller
rauldmiller at gmail.com
Tue Sep 5 15:31:19 UTC 2017
It's probably worth noting that a meta refresh tag - see
http://blooberry.com/indexdot/html/tagpages/m/meta.htm for some docs -
is one that would look like this:
<meta http-equiv="Refresh" content="3; URL=http://localhost:65001/message" />
But what this is doing, in essence, is creating an http header that
would look like this:
Refresh: 3; URL=http://localhost:65001/message
In other words, rather than doing this:
MYTEMPLATE=: 0 : 0
HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Connection: close
<html>
<head>
<meta http-equiv="Refresh" content="3; URL=http://localhost:65001/message" />
</head>
<body>
<pre>
PAGECONTENT
</pre>
</body>
</html>
)
(or, optionally, eliminating the html and body tags, since the browser
should reconstruct them for us)
you could achieve the same thing by doing this:
MYTEMPLATE=: 0 : 0
HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Connection: close
Refresh: 3; URL=http://localhost:65001/message
<pre>
PAGECONTENT
</pre>
)
You could also probably remove the ';
URL=http://localhost:65001/message' part - I think the browser would
use the page's url if the refresh url is not specified.
Finally, note that those name: value HTTP headers can be arranged in any order.
I could go on, but hopefully this is enough to understand something
about this option.
Thanks,
--
Raul
On Tue, Sep 5, 2017 at 9:18 AM, Stefano Lanzavecchia <stf at apl.it> wrote:
> A META header in the <Head> section of the HTML page can force a recurrent refresh. The first article Google found on the subject is this one: http://www.htmlgoodies.com/tutorials/getting_started/article.php/3479551 The article also shows a micro-snippet in JavaScript to obtain a similar effect on a user click.
>
> In order to obtain a similar effect under program control, where the server decides when it's time to upgrade, one needs to keep a channel opened between the browser and the server. This implies tricky JavaScript code client-side and tricky code server side. Modern browser can leverage so-called websockets (https://en.wikipedia.org/wiki/WebSocket) as long as the server is up to the game. There are fallback strategies (https://stackoverflow.com/questions/7807066/how-signalr-works-internally/7874352#7874352). In general, having a full-duplex communication between a browser and a web server is possible but it's not trivial and its complexity depends, among various other things, on the level of compatibility required. Personally, before embarking in anything more complex, I would try and see if the Meta Refresh tag is good enough.
>
> Good luck!
> --
> Stefano
>
> -----Original Message-----
> From: Programming [mailto:programming-bounces at forums.jsoftware.com] On Behalf Of Raul Miller
> Sent: martedì 5 settembre 2017 14:54
> To: Programming forum <programming at jsoftware.com>
> Subject: Re: [Jprogramming] How can I auto-refresh a JHS app page?
>
> That's pretty much it. The browser is in control here, and jijx is only indirectly in control as a result.
>
> Probably the simplest would be to put something like Refresh: 3 in the http headers in your MYTEMPLATE (before the first blank line). But I haven't tested that - I probably need to upgrade my jhs implementation before your code would work for me.
>
> Thanks,
>
> --
> Raul
>
>
> On Tue, Sep 5, 2017 at 8:27 AM, Ian Clark <earthspotty at gmail.com> wrote:
>> Currently I'm hacking it by using Keyboard Maestro to execute a timer which
>> reloads the message URL every 3 seconds.
>>
>> I guess much the same thing could be done using Javascript embedded in
>> message.ijs? – if I knew any Javascript.
>>
>> Another expedient is to write out the message display to a textfile
>> (~/message.txt) and open it using TextWrangler. This (unlike TextEdit)
>> refreshes its display window whenever message.txt is rewritten.
>>
>> But these expedients are inelegant. I guess web browsers were not designed
>> to do this sort of thing. (Or designed not to do this sort of thing?)
>>
>> On Tue, Sep 5, 2017 at 2:59 AM, Ian Clark <earthspotty at 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
More information about the Programming
mailing list