SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Mar 2004
    Location
    Chambéry (France)
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    cannot create DIV elements in IE4 (problems in X)

    I'm having problems with the dynamic creation of div elements within the X Library.
    Mike Foster proposed a helpful support for NN4 with the xCreateElement() function. But when creating elements in IE 4.0 or Opera, no element is returned.
    I think I have found the reason :
    http://msdn.microsoft.com/workshop/a...ateelement.asp
    To resume : the only new elements that can be created are img, are and options.
    I wrote this but don't know how to fix it.
    Code:
    function xCreateElement(sTag)
    {
      var ele=null;
      if (document.createElement) {
        //test if DIV creation is possible
        if (document.createElement('DIV')) ele = document.createElement(sTag);
        else alert ('no DIV creation possible');  // may happen in IE4.0, Mozilla ?
      }
      else if (xNN4) ele = new Object();
      return ele;
    }
    Any idea ?
    Thanks

  2. #2
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi pgira,

    I don't think this: "else alert ('no DIV creation possible');" should be in the library code. You should check the return value in your application code. This is the conventional approach. If xCreateElement or xAppendChild return null, then your app should gracefully downgrade. They will properly return null in IE4 and Opera6.

  3. #3
    SitePoint Member
    Join Date
    Mar 2004
    Location
    Chambéry (France)
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The big problem is that the initial test (I modified) if (document.createElement) does return true in IE 4.0. And so, ele cannot be null.

    In opposite, if (document.createElement('DIV') returns false.

    Do you have any suggestion to even create div elements in IE 4.0 or Opera ?

    Great thanks.

    Pierre

    ps : I have little suggestions to add in your documentation, how to contribute ?

  4. #4
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi pgira,

    sorry, I forgot about this thread

    try this:

    Code:
    // x_dom_nn4.js, X v3.15.2, Cross-Browser.com DHTML Library
    // Copyright (c) 2004 Michael Foster, Licensed LGPL (gnu.org)
    
    // Returns a new Element object.
    // For NN4, returns a new Object object - xAppendChild will return the Layer object.
    function xCreateElement(sTag)
    {
      var ele=null;
      if (xOp5or6 || xIE4) return null;
      if (document.createElement) ele = document.createElement(sTag);
      else if (xNN4) ele = new Object();
      return ele;
    }
    function xAppendChild(oParent, oChild, nn4Width) // returns oChild
    {
      var ele=null;
      if (!oChild) return;
      if (oParent && oParent.appendChild) ele = oParent.appendChild(oChild);
      else if (xNN4) {
        if (typeof(oChild)=='object') delete oChild;
        if (!oParent || oParent.id.indexOf('_layer')==-1) {
          oParent = window;
          if (!nn4Width) nn4Width = xClientWidth();
        }
        else if (!nn4Width) nn4Width = xWidth(oParent);
        ele = new Layer(nn4Width, oParent);
      }
      return ele;
    }
    Do you have any suggestion to even create div elements in IE 4.0 or Opera ?
    No.

    I have little suggestions to add in your documentation, how to contribute ?
    Start another thread or shoot me an email: mike(at)mfoster.com

    Thanks

  5. #5
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just noticed that you are mentioning Opera without giving the version. createElement does work in O7, but not O5 nor O6.

    I use O7 all the time


Bookmarks

Posting Permissions

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