Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!nntp.club.cc.cmu.edu!micro-heart-of-gold.mit.edu!bloom-beacon.mit.edu!panix!not-for-mail From: Xox Newsgroups: comp.lang.javascript Subject: Re: Shutting script down when leaving page Date: Mon, 27 Jan 2014 19:43:38 +0000 (UTC) Organization: PANIX Public Access Internet and UNIX, NYC Lines: 72 Message-ID: References: <6507961.N3xZG9CObR@PointedEars.de> <270120141041247876%timstreater@greenbee.net> NNTP-Posting-Host: pool-74-108-80-123.nycmny.east.verizon.net Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: reader1.panix.com 1390851818 23820 74.108.80.123 (27 Jan 2014 19:43:38 GMT) X-Complaints-To: abuse@panix.com NNTP-Posting-Date: Mon, 27 Jan 2014 19:43:38 +0000 (UTC) User-Agent: Pan/0.136 (I'm far too busy being delicious; GIT 926a150 git://git.gnome.org/pan2) Xref: csiph.com comp.lang.javascript:22825 On Mon, 27 Jan 2014 10:41:24 +0000, Tim Streater wrote: > In article <6507961.N3xZG9CObR@PointedEars.de>, Thomas 'PointedEars' > Lahn wrote: > >> Andrew Poulos wrote: >> >> > On 27/01/2014 2:25 PM, Xox wrote: >> >> Let us suppose I have a page, a.html, which contains a script which >> >> constantly invokes itself or is invoked -- it's running not >> >> necessarily continuously but at regular intervals, or maybe it is >> >> looping. >> >> There are no pages, they are not “running”, and they certainly do not >> “loop”. Scripts do not “invoke themselves” either. >> >> Script code may cause other code to be executed repeatedly, using the >> browser API, and it may cause a resource in a view to be reloaded, upon >> which it could be executed again if it was part of that resource. That >> is not a loop. > > Yet more sneering by PointyHead at people's "incorrect" use of > terminology. Still, I expect it's how he's used to treating his > students, if any. > >> > Perhaps calling onunload and/or onbeforeunload and stopping the >> > script will help. >> >> “onunload” and “onbeforeunload” are event-handler attributes and >> properties. >> They cannot be called by the developer to the desired effect because >> the developer does not know when they should call them in the first >> place. >> >> There is an unfortunate tendency of saying that something is “called” >> when any action is caused by anything, particularly among beginners. >> People nonsensically speak of “Ajax calls”, for example. > > var request = new XMLHttpRequest (); > ... > request.send (data); > > Hmmm, looks like a function call to me. > > If PointyHead were less of an arsehole, he might have simply reassured > the OP by describing what happens to a page being displayed, and its > resources, when the user navigates to another page. IOW, behaved like a > good teacher. But no. Instead, he feels an irresistible urge to demean > posters by making corrections to their usage of terminology, and their > manner of posting. I am sorry my vocabulary offended. (Although I don't know what the statelessness of HTTP has to do with anything.) I will explain in another way. I have a page which has some Javascript functions on/in it. Some of the functions are repeatedly called/started/invoked/run by setInterval or setTimeout. They look to see whether certain objects etc. are present and where they are, and may move or create other objects accordingly. There could be a lot of these objects. The functions could thus consume a lot of resources. Now suppose the browser navigates to another page. I am wondering whether some browsers may continue to execute the aforesaid function invocations anyway. I would think not, but stranger things have been coded. I could make a list of the ids returned by setInterval and run clearInterval against each on the onunload event, but I'd just as soon not bother if it's superfluous. Does anyone know?