Set onclick from an opened window

B

believein

Hi all,
I'm playing with javascript DOM and I enjoyed but now I stopped
on a problem I can't solve.
I need to set the 'onclick' on a <div> tag in the opener window from
code in the opened window.

The following code works (without the 'window.opener' prefix) if
executed in the inner of the window. If I use it from the opened window
the tag is created but the 'onclick' not.

var para=window.opener.document.getElementById('images');
var div = window.opener.document.createElement('div');
div.id = "theid";
with (div.style) {
cursor='pointer';
}
div.onclick = function() {
thefunction();
}
div.innerHTML="The text";
para.appendChild(div);

If used in the same window it returns
<div style="cursor: pointer" id="theid" onclick="thefunction();">The
text</div>

while if used in the opened window to create the tag in the opener
window it returns:
<div style="cursor: pointer" id="theid">The text</div>

Any idea?

Thank you
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top