onclick and DOM in parent window problem

F

Flyzone

Hi,
i have a child window (windows.open) and and a parent table create by
dom.
Running these lines from child window:

var myTd7=window.opener.parent.document.createElement('td');
myTd7.setAttribute("class","adminfield");
var myTd7a=window.opener.parent.document.createElement('a');
myTd7a.setAttribute("href","javascript:void(0)");
myTd7a.setAttribute("onclick","javascript:deleteRow(this)");
var myTd7img=window.opener.parent.document.createElement('img');
myTd7img.setAttribute("alt","Delete");
myTd7img.setAttribute("border","0");
myTd7img.setAttribute("src","img/delete.png");

to add a new td with a img. Clicking on the img will be run deleteRow
function that is write on the parent window:
function deleteRow(r) {
var i=r.parentNode.parentNode.rowIndex;
document.getElementById('db_list').deleteRow(i);
}

Problem: in FF all ok, in IE simply the onclick is not working, no
error, like if is not called. Looking with the IE Developper Toolbar
the onclick attribute is set. Trying an if
(window.addEventListener)...does not solve.

Where have I wrong?
Thanks in advance
 
M

Martin Honnen

Flyzone said:
var myTd7=window.opener.parent.document.createElement('td');
myTd7.setAttribute("class","adminfield");

Use properties, not setAttribute:
myTd7.className = "adminfield";
var myTd7a=window.opener.parent.document.createElement('a');
myTd7a.setAttribute("href","javascript:void(0)");

myTd7a.href = "#";
myTd7a.setAttribute("onclick","javascript:deleteRow(this)");

myTd7a.onclick = function () { deleteRow(this; };
 
F

Flyzone

Martin Honnen ha scritto:
Use properties, not setAttribute:
myTd7.className = "adminfield";

Sorry, which is the difference?
myTd7a.onclick = function () { deleteRow(this); };

Done, but however i have the same problem...nothing is done and no
error appear...
I have also an "alert" into the function but is not executed. :-/
 
T

Thomas 'PointedEars' Lahn

Flyzone said:
Martin Honnen ha scritto:

Sorry, which is the difference?

The difference is, since Element::setAttribute() is known to suffer from
a number of buggy implementations, you should use the attribute property
instead of E::setAttribute() where there is one.
Done, but however i have the same problem...nothing is done and no
error appear...
I have also an "alert" into the function but is not executed. :-/

Then the error is likely to be elsewhere, and you should debug your code:

http://www.jibbering.com/faq/faq_notes/clj_posts.html#ps1DontWork
http://jibbering.com/faq/#FAQ4_43
http://jibbering.com/faq/#FAQ3_2

<FAQENTRY>
As mentioned earlier, the FAQ Notes entry "Don't work" should refer to
FAQ 4.43.

FAQ 4.43 should refer to to FAQ 3.2 since debuggers help to show
non-obvious errors.

FAQ 3.2 should be structured better. It desperately needs one or more
unordered lists and to contain at least one subsection titled "Debuggers",
which should at least include references to Venkman, the debugger in
Firebug, and the Microsoft Script Debugger.

Opera 9.x and Apple Safari 3.x provide pretty neat developer tools as
well:

* http://dev.opera.com/tools/

* http://developer.apple.com/internet/safari/faq.html#anchor14
(The information there appears to be slightly out of date; you need
to put that key into WebKitPreferences.plist instead. YMMV.)
</FAQENTRY>

That said, you may have better luck with the standards-compliant approach,
and the proprietary one only as a fallback:

function isMethod(o, p)
{
var t;
return o && /\b(function|object|unknown)\b/i.test(typeof o[p]) && o[p];
}

var o = myTd7a,
f = function() { deleteRow(this); };

if (isMethod(o, "addEventListener"))
{
o.addEventListener("click", f, false);
}
else if (typeof o.onclick != "undefined")
{
o.onclick = f;
}


HTH

PointedEars
 
F

Flyzone

function isMethod(o, p)

I solved the problem.
In the source HTML i neede to add also the <tbody> tag, that FF add by
itself using the dom, but IE need to show the new table.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,681
Members
48,796
Latest member
Greg L.

Latest Threads

Top