@jscheuer, soemthing else, I'm postiv surprised for now, that a mod came around and clear some here. I cant send a pm, so keep it short.
@jscheuer, soemthing else, I'm postiv surprised for now, that a mod came around and clear some here. I cant send a pm, so keep it short.
The main difference about what's being done in the video is that it takes into account Internet Explorer 8 and less - those browser's inability to follow the standard event model. Virtually no one uses those browsers, so their proprietary attachEvent method no longer needs to be a part of any modern code.
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
I can go a little further. If you do want make this code backward compatible with older IE versions (all the way to IE 5), you can do this:
But it's entirely unnecessary unless you need to support these older browsers, which, as I've said, virtually no one uses any longer. If you want to be useful in all sorts of environments, it can be good to know how to cater to antiquated software/machines (it's the older machines that are limited sometimes to run older software). This is only critical if your target audience is in a (internet technology speaking sense) backward country or organization.Code:<!DOCTYPE html> <html> <head> <title>Add Event Listener Demo</title> <meta charset="UTF-8"> <script> function addListeners(){ if(window.addEventListener){ document.getElementById('mybtn').addEventListener("click", btn1func, false); } else if(window.attachEvent){ var el = document.getElementById('mybtn'), oldbtn1func = btn1func; btn1func = function(){oldbtn1func.apply(el);}; el.attachEvent('onclick', btn1func); } } function btn1func(){ alert(this.id + " : mouse-click makes script run" ); } if(window.addEventListener){ window.addEventListener('load', addListeners, false); } else if(window.attachEvent){ window.attachEvent('onload', addListeners); } </script> </head> <body> <button id="mybtn">MyButton</button> </body> </html>
Last edited by jscheuer1; 02-09-2018 at 10:15 PM. Reason: minor code improvements
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
well, I dont know what to tell, thanks of course.
Hope thats the reason for all the other exmples from which I picked up the code and nothing happend.
Is there any way to proof that? Lets say maybe with another IDE?
Integrated development environment? Yes, that would do it if it included those earlier browsers. But one can use IE 11 and it's developer console's emulation feature to see what earlier IE versions would make of code. There are some limitations. But it's mostly accurate. I have the advantage of previous experience, so you can 99% trust what I just told you. To be 100% sure you would have to find a way to test in the actual browsers.
Something I would add, even for people who are limited by their machines as to what IE version they can run, those people almost always have the option of running an older version of Netscape and/or Firefox, both of which adopted the standard event model long before IE did. Because of that, and the fact that very few people are so limited, I tend to advise against trying to be so backward compatible unless you know for a fact that's necessary. That said, there are times when your target audience will be limited to both an older machine and an older version of IE. That's increasingly rare, but it still could at least theoretically happen. For general purposes though, just sticking to the standard event model* is more than adequate.
*Standard Event Model (as previously posted):
Code:<!DOCTYPE html> <html> <head> <title>Add Event Listener Demo</title> <meta charset="UTF-8"> <script> function addListeners(){ document.getElementById('mybtn').addEventListener("click", btn1func, false); } function btn1func(){ alert(this.id + " : mouse-click makes script run" ); } window.addEventListener('load', addListeners, false); </script> </head> <body> <button id="mybtn">MyButton</button> </body> </html>
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
I have no doubt, but I dont think you want to ask me here all the time I have tried any new youtube example.I have the advantage of previous experience, so you can 99% trust
I'm not an english native, I've read your answer many times, would straight agree that I missanderstand any of it, but cant see what it is.
some other videos, there are more, none of the code shows any reaction.
https://www.youtube.com/watch?v=NO-U0vP5ikA
https://www.youtube.com/watch?v=AnOAZsezLEg
Have you ever heard about the krueger Effekt? Some kind of proof like, why stupid people easier belive themselfs ****ing smart
Last edited by jscheuer1; 02-15-2018 at 07:25 PM. Reason: format
Bookmarks