SitePoint Sponsor |
|
User Tag List
Results 1 to 5 of 5
-
Mar 18, 2004, 05:12 #1
- 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; }
Thanks
-
Mar 18, 2004, 10:58 #2
- 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.Cross-Browser.com, Home of the X Library
-
Mar 18, 2004, 11:33 #3
- 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 ?
-
Mar 20, 2004, 09:20 #4
- 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 ?
I have little suggestions to add in your documentation, how to contribute ?
ThanksCross-Browser.com, Home of the X Library
-
Mar 20, 2004, 09:23 #5
- 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 timeCross-Browser.com, Home of the X Library
Bookmarks