Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    kae
    kae is offline
    New to the CF scene
    Join Date
    Mar 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    cross-browser events API

    hi all,
    I'm completely new to this forum, so if this question has been asked a thousand times before, please simply post a URL. thanks

    now, my company's bosses have been becoming increasingly frustrated at me recently, as I tend to code for Firefox first, and IE as an afterthought.

    a lot of the code I have trouble with is events-based, although there are some DOM-navigation problems that I've noticed in IE.

    before I launch into a probably fruitless attempt to write an API that corrects IE's DOM-mangling, I'm wondering if someone else may have already invented that particular wheel.

    ideally, this would be a script which I simply link to in the head, and then write valid DOM code which automagically works.

    Thanks,
    Kae

  • #2

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,048
    Thanks
    0
    Thanked 251 Times in 247 Posts
    I found a cross-browser events API here

  • #4
    kae
    kae is offline
    New to the CF scene
    Join Date
    Mar 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Glenn.

    Unfortunately, those links don't really answer the question I had, although they may help me if I do need to build an API myself.

    What I was hoping for was something that would allow me to write code such as this:

    <html>
    <head>
    <script type="text/javascript">
    window.addEventListener('click',function(){alert('test');},false);
    </script>
    </head>
    <body>
    </body>
    </html>

    The above code will work in Firefox, but not IE.

    I can make it work by first defining addEventListener for IE:

    window.addEventListener=function(ev,fn){window.attachEvent('on'+ev,fn);}

    unfortunately, that's a rather cumbersome way of doing it, as I would have to specifically fix every element in the document, and be aware that the fix may not apply to dynamically generated elements.

    an ideal solution would be to apply the events fixes to the object prototypes, but IE seems to completely ignore inheritance, so there's no point doing that.

    Kae

  • #5
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Have a look at my "encapsulated anonymous functions" thread - you might like that approach -- Binding encapsulated anonymous functions without repetition

    But what this question comes down to, as you're seeing, is that browsers vary hugely, and there is no unified model; maybe there would be if IE wasn't so outdated, but whatever ... it's as it is

    The best approach to most scripting is to start from the assumption that everything works as it's supposed to, unless it's known not to; then hack from there until you've covered or excluded the browsers you care about. Effectively, write for the correct case (which is usually, but not always, what Firefox does), plus exceptions (IE builds, Safari, Opera ... as necessary).
    Last edited by brothercake; 03-17-2005 at 11:11 AM.
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

  • #6
    kae
    kae is offline
    New to the CF scene
    Join Date
    Mar 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ah! that's an interesting approach.

    I think it will take a bit of practice for it to sink in for me, but it does look like that's what I need.

    Thanks.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •