[thelist] xml in javascript ie does show it

Jeff Howden jeff at jeffhowden.com
Wed Oct 26 03:52:54 CDT 2005


Hi,

><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> From: gruppenfreizeit
> 
> Then I created and entered in a loop 2 elements into
> the table.  Both elements are not retouched by some
> scripts.
> 
> print 'var el = x.createElement("TD");';
> print 'el.onclick = function(){alert("'.$x.'");};';
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><

When posting examples, *please* just post the JS and not the extra bits
you're using server-side to generate it.

><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> It should give an alert with the value 4 for the first
> TD and an alert with the value 5 for the 2 TD.
> IE allows one click in one of both TDs and returns the
> right value.  Then the function is gone.
> Mozilla works fine.
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><

There must be something going on with your app specifically because the
example I posted earlier in this thread proves that what you claim does
*not* happen when coded properly.

http://dev.jeffhowden.com/thelist/ierowclick.html

I've even added some additional coloring to indicate the row or cell has
received an event more than once and successfully processed the anonymous
function attached to that event.

><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> next was
> print
> 'window.parent.chatinfo.document.getElementById("tdx").onclick
> =window.open()
> ;';
> a window is opened automatically
> even with
> print
> 'window.parent.chatinfo.document.getElementById("").whatToHell
> =window.open()
> ;';
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><

This is incorrect coding.  Omit the parenthesis and it *should* work as
expected.

window.parent.chatinfo.document.getElementById('tdx').onclick = window.open;

Honestly, that's *way* to much in one line of code without so much as a
single check in the process.  Better to be safe than sorry, I say.  With
that in mind, here's how I'd do it:

var oParent = window.parent;
var oChatinfo = null
var oTDX = null
if(oParent)
{
  oChatinfo = oParent.frames['chatinfo'];
  if(oChatinfo && oChatinfo.document)
  {
    oTDX = oChatinfo.document.getElementById('tdx');
    if(oTDX)
      oTDX.onclick = window.open;
  }
}

Yes, more lines of code.  Yes, far more verbose.  However, if any of the
elements in the chain become unavailable for whatever reason, my code will
swallow up that problem without flooding the user with JS errors.

 [>] Jeff Howden
     jeff at jeffhowden.com
     http://jeffhowden.com/




More information about the thelist mailing list