JS: window.myid and document.myid

Koos Vriezen koos.vriezen at xs4all.nl
Tue Jun 17 18:22:53 BST 2003


On Sun, 15 Jun 2003, George Staikos wrote:

> On Sunday 15 June 2003 08:25, Koos Vriezen wrote:
> > Hi,
> >
> > Shouldn't tags like <OBJECT ID='myid'> also be found with document.myid
> > (currently in HEAD only window.myid works)?
>
>    It seems that at least some sites expect the object id to be a child of the
> document node.  I saw this recently as well.

Did some testing today with

  <html><head><script>
  function showIt() {
    var str = "document.mytable=" + document.mytable + "\n";
    str += "window.mytable=" + window.mytable + "\n";
    alert (str);
    var str = "document.myobj=" + document.myobj + "\n";
    str += "window.myobj=" + window.myobj + "\n";
    alert (str);
    var str = "document.myemb=" + document.myemb + "\n";
    str += "window.myemb=" + window.myemb + "\n";
    alert (str);
  }
  </script></head>
  <body onClick="showIt()"><table id="mytable"></table>
  <object id="myobj"></object><embed id="myemb"></embed>
  </body></html>

And it seems konqueror is the only one not supporting document.id on
OBJECT. Don't know why IE doesn't support it on EMBED but I've seen
document.id on EMBEDs too IIRC, maybe because in this test it has no
servicetype set.

                      window.id                 document.id
konqueror 3.1.2   mytable/myobj/myembed               -
IE 6              mytable/myobj/myembed            myobj
Mozilla 1.3               -                     myobj/myembed

I think it's good to support document.id on OBJECT and at least APPLET
elements too (see attached patch).

Koos
-------------- next part --------------
Index: ecma/kjs_html.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/ecma/kjs_html.cpp,v
retrieving revision 1.250
diff -u -3 -p -r1.250 kjs_html.cpp
--- ecma/kjs_html.cpp	17 Jun 2003 10:08:36 -0000	1.250
+++ ecma/kjs_html.cpp	17 Jun 2003 17:15:59 -0000
@@ -382,6 +382,14 @@ Value KJS::HTMLDocument::tryGet(ExecStat
   if (DOMDocument::hasProperty(exec, propertyName))
     return DOMDocument::tryGet(exec, propertyName);
 
+  // allow shortcuts like 'MyApplet1' instead of document.applets.MyApplet1
+  if (doc.isHTMLDocument()) { // might be XML
+    DOM::HTMLCollection coll = doc.applets();
+    DOM::HTMLElement element = coll.namedItem(propertyName.string());
+    if (!element.isNull()) {
+      return getDOMNode(exec,element);
+    }
+  }
 #ifdef KJS_VERBOSE
   kdDebug(6070) << "KJS::HTMLDocument::tryGet " << propertyName.qstring() << " not found" << endl;
 #endif


More information about the kfm-devel mailing list