Been having a lot of work on customizing Dokeos for a client, so didn’t really have any spare time to write. Least useful error yet.This post is about common mistakes or overlooks when developing RIAs with JavaScript.
First of all, something to always keep in mind when working with Internet Explorer: it will never ever act like you wish from the first time.

Pay extra attention especially when dealing with DOM elements, as it tends to throw errors that FF doesn’t - I’m not talking about the fact that IE is not DOM compliant and methods that work in Mozilla family browsers don’t exist in IE or have different names.
Here’s a list of things to remember:

  1. If you want to get things done fast, use a framework - Prototype does an excellent job.
  2. HTMLElement is not accessible in IE, so in order to extend it, few hacks are necessary (first is to use Element.extend from prototype, or have a look at this: http://www.geekdaily.net/2007/06/18/javascript-htmlelement-in-ie/.
  3. Always use $() from prototype when dealing with extended DOM elements, otherwise IE will issue errors. A short example from Prototype’s api:
    // this will error out in IE:
    $('someElement').parentNode.hide()
    // to make it cross-browser:
    $($('someElement').parentNode).hide()
    

    Read more here.

  4. element.cloneNode() clones a node for the entire execution of the script. In other words, any modification to the original element will also reflect in the clone.
  5. Chained lists in IE. If you want to custom build them, you’ll find out that an option element cannot be hidden (option_element.style.display=”none” won’t work). Furthermore, if you want to delete it, that doesn’t work unless it has an id (<option name=”2″ value=”2″ >2</option> cannot be deleted).
    Another frustrating thing in IE is that sometimes element.innerHTML doesn’t always work as expected.
    If you manipulated the DOM elements, removing or replacing them, for example, then any change using innerHTML in the parent node won’t work, as some child element debrie still remains. Use $(”my_element”).update(html_content_goes_here) instead.
    If I have time I’ll post some examples.
  6. Checking node existence in IE is a bit tricky. For example, suppose you need something like:
    if ($(”something”).previousSibling.firstChild) { // code here } which works flawlessly in FF.
    That will only work in IE if previousSibling exists, if not it gives an Object required error. So to make it correct, use something like:
    if ($(”something”).previousSibling && if $(”something”).previousSibling.firstChild)
  7. A handy function to obtain a variable reference (although true variable reference doesn’t exist in JavaScript) :
    function reference_to(property ) {
    	return window[property];
    }
    // usage
    var einstein = “something”;
    alert(reference_to(”einstein”));
    // ouputs: something
    // If you want the reference from an object member variable or method extend the function by
    // replacing window with the desired object.
    
Save and share: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • Sphinn
  • del.icio.us
  • Mixx
  • Google
  • StumbleUpon
  • Technorati
  • YahooMyWeb

Comments

3 Responses to “IE Object required error and other common coding mistakes”

  1. Tanya Knepper on November 8th, 2008 2:19 am

    Hi

    I am getting this error on my vertical scroll menu (object required) in IE. The menu runs flawlessly in other browsers but it tends to stick and take a while to open in explorer and i get that error in the left corner when i do. Would you be able to suggest something in that situation please.

    Thank you

  2. Bogdan on November 13th, 2008 9:28 pm

    Hi!

    Check to have an id set for the element you’re trying to manipulate.
    Other than that, donno until I see the code.
    P.S. Use jQuery ;)

  3. David on October 24th, 2009 2:01 pm

    Hi!
    I get the error “object required” when IE-visitors watch video-clips. It is when they want to go back or leave the page the error shows up!!
    Please help me with this!!
    If you send me an e-mail I can tell you more about the codes I´m using

    /David

Leave a Reply




Advertisements