Path: csiph.com!weretis.net!feeder4.news.weretis.net!feeder5.news.weretis.net!news.solani.org!.POSTED!not-for-mail From: Thomas 'PointedEars' Lahn Newsgroups: comp.lang.javascript Subject: Re: Which type of network access for this situation? Date: Tue, 18 Apr 2017 02:52:14 +0200 Organization: PointedEars Software (PES) Lines: 53 Message-ID: <1611458.0Y0JHutS3l@PointedEars.de> References: <7e444aec-2938-4da7-9162-54b71bbe7be7@googlegroups.com> Reply-To: Thomas 'PointedEars' Lahn Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit X-Trace: solani.org 1492476735 27680 eJwFwQEBACAIA7BKID/eOIrSP4IbIz1rIplgs4V9Vt0NcT21GwrwG+DUFM9ZFmzrkj17Y3wW+xCq (18 Apr 2017 00:52:15 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Tue, 18 Apr 2017 00:52:15 +0000 (UTC) User-Agent: KNode/4.14.2 X-User-ID: eJwNxkkBwDAIBEBL4QY5QLL+JbTzGhMn31A3V4Oh38yieu4cWGRzLx0pEcPbpn/E7pxpESWX/aSCkt40tO4HclEVkw== X-Face: %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&. bit-naughty@hotmail.com wrote: >> Suppose after a page is loaded, I want to download some stuff (text or >> HTML) later, or even immediately and display it. But NOT on a button >> click, more like say, after a timer goes off or something. What type of >> networking shit do I use for this? Does it call for AJAX, WebSockets or >> the DataChannel part of the WebRTC API, which I just got to know about? >> I'm still not really clear about what the exact differences between each >> of them are.... > > Use the XMLHttpRequest object. […] Not necessarily. If a resource is to be downloaded to be saved as a file in the filesystem in a user-specified location after a “timer goes off”, then a simple var timer = window.setTimeout(function () { window.clearTimeout(timer); window.location = "…"; }, 42); suffices, where 42 is the number of milliseconds after this call that the “timer goes off” (in backwards-compatible code, it should not be less than 10). The resource needs to be served with the proper MIME media type; if it should be downloaded to be saved as a file, then “application/octet-stream” will trigger the browser’s download dialog. Any suitable set of statements can be used instead of the assignment to “window.location”. For example, if an image resource is to be displayed, code to set the “src” property of an “img” element object, optionally create the latter and insert the corresponding “img” node into the document tree first, can be used. If one uses window.setTimeout(), one should also handle the case of navigating away before the “timer goes off”, so as not to potentially execute code that potentielly produces errors because of missing objects: window.onunload = function () { window.clearTimeout(timer); }; It may be useful to establish a timeout registry that clears all registered timeouts in that case. The usual caveats regarding the use of host-provided features apply. -- PointedEars FAQ: | | Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.