From: David Mark on 20 Jul 2010 14:16 On Jul 20, 12:16 pm, William Wallace <wbravehea...(a)googlemail.com> wrote: > On Jul 20, 6:07 pm, Erwin Moller > > > > > > <Since_humans_read_this_I_am_spammed_too_m...(a)spamyourself.com> wrote: > > William Wallace schreef: > > > On Jul 20, 5:00 pm, Erwin Moller > > > <Since_humans_read_this_I_am_spammed_too_m...(a)spamyourself.com> wrote: > > >> William Wallace schreef: > > > >>> Am I right in thinking that I want to use document.addEventListener / > > >>> document.attachEvent for the following events? > > >>> load, unload, resize, scroll and mousemove. > > >> Hard to tell. > > > >> You can also do it like this: > > > >> <body onLoad="whatever();" onUnLoad="whatever2();"> > > > >> Why do you want to use addEventListener ? > > >> If you give more context, the good people in here can give you better > > >> advise. > > > > I'm doing everything from an included JS file, so I don't get to > > > determine what's in the body tag. I find that on this group, the less > > > context given the better. They just pick apart everything you say if > > > you give more detail. > > > Ok, but what is your question then? > > Here it is again: > > Am I right in thinking that I want to use document.addEventListener / > document.attachEvent for the following events? > > load, unload, resize, scroll and mousemove. For load and unload, it depends on the context (i.e. is the body available). For resize and scroll, I believe attaching to window is the most compatible (and makes logical sense). For mousemove, definitely not.
From: William Wallace on 20 Jul 2010 14:54 On Jul 20, 8:16 pm, David Mark <dmark.cins...(a)gmail.com> wrote: > > Am I right in thinking that I want to use document.addEventListener / > > document.attachEvent for the following events? > > > load, unload, resize, scroll and mousemove. > > For load and unload, it depends on the context (i.e. is the body > available). For resize and scroll, I believe attaching to window is > the most compatible (and makes logical sense). For mousemove, > definitely not. Thanks a lot David. Now we're getting somewhere :) The body is definitely available. So I've now got my list of whether to use window or document. Use window.* for resize/scroll events. Use document.* for all mouse events and load/unload. It's part of something for a corporate website, there's nobody showing up with IE4 or Netscape 6. It's basically just the most recent few versions of IE, FF, Chrome, Safari and Opera. Not that I'm doing useragent sniffing or anything, I'm just saying what my test range is. I'll be doing feature testing. The problem I found is that feature testing didn't tell me whether I should prefer window or document because both had the add/remove EventListener (or attach/detach Event for IE).
From: David Mark on 20 Jul 2010 15:19 On Jul 20, 2:54 pm, William Wallace <wbravehea...(a)googlemail.com> wrote: > On Jul 20, 8:16 pm, David Mark <dmark.cins...(a)gmail.com> wrote: > > > > Am I right in thinking that I want to use document.addEventListener / > > > document.attachEvent for the following events? > > > > load, unload, resize, scroll and mousemove. > > > For load and unload, it depends on the context (i.e. is the body > > available). For resize and scroll, I believe attaching to window is > > the most compatible (and makes logical sense). For mousemove, > > definitely not. > > Thanks a lot David. Now we're getting somewhere :) Possibly. > The body is > definitely available. So I've now got my list of whether to use window > or document. > > Use window.* for resize/scroll events. I don't think you can go wrong there. But realize this is not a standard. You need to detect whether window.addEventListener exists at all. > > Use document.* for all mouse events and load/unload. No. Use the body for load/unload. And in fact, don't use unload at all as it breaks fast history navigation (and there's rarely a good reason to use it anyway). > > It's part of something for a corporate website, there's nobody showing > up with IE4 or Netscape 6. Hmmm. Is there nobody showing up with Netscape 6 because nobody is using that browser or because the site breaks in that browser? Clearly nobody (sane) uses Netscape 6 these days, but do you see the problem with such (commonly expressed) assumptions? And if you follow my advice, at least as far as attaching these listeners goes, you won't have any trouble with those browsers anyway. > It's basically just the most recent few > versions of IE, FF, Chrome, Safari and Opera. What is? Are you reading from usage statistics? See above. :) > Not that I'm doing > useragent sniffing or anything, Good. > I'm just saying what my test range is. The last few versions of the above browsers is not necessarily a bad range. Compared to most Web (and even library) developers it is admirable. Just be careful of reading too much into positive results. You have to have some understanding of each and every line of code to be reasonably sure that it will work in the myriad browsers/ configurations that you did not test. > I'll be doing feature testing. Good. In many cases feature detection is all that is needed. Feature testing comes in to play when features exist but are known to be buggy in some cases (this is where the libraries typically regress back to browser sniffing). Taken to an ultra-paranoid extreme you could assume this about all features. But of course, not all features are easily testable. It's an imperfect world, but with experience and good practice, you can approach perfection rather than flirting with disaster. > The problem I found is that feature > testing didn't tell me whether I should prefer window or document > because both had the add/remove EventListener (or attach/detach Event > for IE). This is where experience (and standards) come into play. There is no standard for window.addEventListener and there are (or at least were) browsers out there that implement document.addEventLister but not window.addEventListener. So you should avoid the window version whenever possible and detect (not test) it before use. So what if window.addEventListener is missing and you need to listen for scroll/resize? I would use document.documentElement myself. The only reason I would not use document.documentElement (or document) for scroll/resize in the first place is for backward compatibility (ISTM that some very old browsers and possibly off-brands available today failed to support scroll/resize listeners on the document object, but I could be thinking of DOM0).
From: David Mark on 20 Jul 2010 15:47 On Jul 20, 12:07 pm, Erwin Moller <Since_humans_read_this_I_am_spammed_too_m...(a)spamyourself.com> wrote: > William Wallace schreef: > > > > > > > On Jul 20, 5:00 pm, Erwin Moller > > <Since_humans_read_this_I_am_spammed_too_m...(a)spamyourself.com> wrote: > >> William Wallace schreef: > > >>> Am I right in thinking that I want to use document.addEventListener / > >>> document.attachEvent for the following events? > >>> load, unload, resize, scroll and mousemove. > >> Hard to tell. > > >> You can also do it like this: > > >> <body onLoad="whatever();" onUnLoad="whatever2();"> > > >> Why do you want to use addEventListener ? > >> If you give more context, the good people in here can give you better > >> advise. > > > I'm doing everything from an included JS file, so I don't get to > > determine what's in the body tag. I find that on this group, the less > > context given the better. They just pick apart everything you say if > > you give more detail. > > Ok, but what is your question then? > > This is what you wrote: > -------------------------------------------- > Am I right in thinking that I want to use document.addEventListener / > document.attachEvent for the following events? load, unload, resize, > scroll and mousemove. > -------------------------------------------- > > Is your question if addEventListener() and attachEvent() can add the > named events? > Is your question if there are more methods to add events? > Is your question what browsers support those methods? > Is your question if there are other methods to add eventListeners? > Do you wonder how to use these methods from your JavaScript file? > etc. > So many possibilities. Do you see why I ask? > > Anyway: I learned a lot from the following articles: > > http://www.quirksmode.org/js/introevents.htmlhttp://www.quirksmode.org/js/events_advanced.html > > No doubt somebody will claim that the above articles suck. ;-) > I don't know if I've read those two in particular, but many of the explanations given on that site do indeed suck. If it just stuck to the empirical evidence gathering, it would be a better site.
From: William Wallace on 20 Jul 2010 15:55 On Jul 20, 9:19 pm, David Mark <dmark.cins...(a)gmail.com> wrote: > Good. In many cases feature detection is all that is needed. Feature > testing comes in to play when features exist but are known to be buggy > in some cases (this is where the libraries typically regress back to > browser sniffing). Taken to an ultra-paranoid extreme you could > assume this about all features. But of course, not all features are > easily testable. It's an imperfect world, but with experience and > good practice, you can approach perfection rather than flirting with > disaster. Had to snip a lot of great info. Saved and absorbed. Dude, write a book, I'll buy a copy. It seems that there are no good books. You could get Thomas to proof-read it. LOL - that would be fun :)
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 4 5 Prev: MBT, my feet's baby Next: CPA AFFILIATE NETWORKS AWESOME EARNINGS FROM YOUR HOME |