Accessing objects from opened window

K

kosmodisk

Hi,

I'm having problem accessing javascript-created elements from opened
window. This occurs only when I'm including another files in opened
window, javascript or css. When I comment out "<link>" and "<script>"
(point (0)), the script works fine.

The opening window itself (point (1)) can access the object. When page
has been loaded, then I can access the object also (point (3)). The
script does find included files (debug_test2.css and debug_test2.js), I
checked that.

Problem appears only on Firefox (my version is 1.5.0.6, on WinXP). On
IE (6.0) works also fine.
Anybody knows cure?


-------code start--------

<script type="text/javascript">

var win = window.open('about:blank', '_blank', '');

with (win.document) {
// (0) remove comments from next 2 rows,
//writeln('<link rel="stylesheet" href="debug_test2.css"
type="text/css" />');
//writeln('<scr'+'ipt type="text/javascript"
src="debug_test2.js"></scr'+'ipt>');
writeln('<table id="test"></table>');
writeln('<scr'+'ipt type="text/javascript">');
// (1) opened window itself has no problem accessing created table
writeln('document.writeln(document.getElementById(\'test\'));');
writeln('</scr'+'ipt>');
}

// (2) outputs NULL when 2 comments above (0) removed, otherwise has no
problems
document.writeln(win.document.getElementById('test') + '<br>');

//-->
</script>

<!-- (3) after page has loaded, I can access the object -->
<input type="submit"
onclick="alert(win.document.getElementById('test')); return false;">

-------code end--------
 
A

ASM

kosmodisk a écrit :
Hi,

I'm having problem accessing javascript-created elements from opened
window. This occurs only when I'm including another files in opened
window, javascript or css. When I comment out "<link>" and "<script>"
(point (0)), the script works fine.
http://stephane.moriaux.perso.orange.fr/truc/copi_clone_popup/

The opening window itself (point (1)) can access the object. When page
has been loaded, then I can access the object also (point (3)). The
script does find included files (debug_test2.css and debug_test2.js), I
checked that.

Problem appears only on Firefox (my version is 1.5.0.6, on WinXP). On
IE (6.0) works also fine.
Anybody knows cure?

something wrong in :
document.write(document.getElementById(\'test\'));
perhaps ?
<script type="text/javascript">

var win = window.open('about:blank', '_blank', '');

var win = window.open(); // will give same result

<script type="text/javascript">

var txt = '<link rel="stylesheet" href="debug_test2.css" '+
'type="text/css" />\n<script type="text/javascript" '+
'src="debug_test2.js"><\/script>\n'+
'<table id="test"><tr><td>a test<\/td><\/tr><\/table>\n'+
'<script type="text/javascript">\n'+
'document.write("\'"+document.getElementById(\'test\')+"\'");'+
'\n<\/script>';

// 1st test :
var win1 = window.open();
win1.document.writeln(txt);

// 2nd test :
var win2 = window.open();
win2.document.open();
win2.document.write('<html><body>\n'+txt+'\n<\/body><\/html>');
win2.document.close();

</script>

<form>
<input type="button" value="see 2"
onclick="alert(win2.document.getElementById('test'));win2.focus();">
<input type="button" value="see 1"
onclick="alert(win1.document.getElementById('test'));win1.focus();
return false;">
<!-- (3) after page has loaded, I can access the object -->
<input type="submit"

<input type="button"
 
K

kosmodisk

Hi,
something wrong in :
document.write(document.getElementById(\'test\'));
perhaps ?
No, this place works fine. This wasn't the problem in the first place.
I checked the link you gave, and I don't think it had any use to me :p
(can't speak any French either :)

I'll explain again:
* javascript code opens new window, and outputs this HTML into this
window:
<link rel="stylesheet" href="debug_test2.css" type="text/css" />
<script type="text/javascript" src="debug_test2.js"></script>
<table id="test"></table>

* now, when i try to access this object from OPENER window ON THE SAME
REQUEST (which means I dont run this code by pushing button or similar)
alert(win.document.getElementById('test'));
// this returns NULL on Firefox.

* when I comment out <link> and <script> lines from output HTML, my FF
gets the object.
alert(win.document.getElementById('test'));
// now it returns HTMLObject or something



Kosmodisk
 
A

ASM

kosmodisk a écrit :
Hi,

No, this place works fine. This wasn't the problem in the first place.
I checked the link you gave, and I don't think it had any use to me :p
(can't speak any French either :)

Dommage :)
I'll explain again:

I understand anything what you mean.
You want to acces to table 'test' in your popup 1 (win1)
while you're calling from popup 2 (win2)
using the opener of this popup 1 ?

if your alert is calling 'win2' form 'win1' :
alert(opener.win2.document.getElementById('test').tagName);

if your alert is calling 'win1' form 'win2' :
alert(opener.win1.document.getElementById('test').tagName);

http://stephane.moriaux.perso.orange.fr/truc/popup_oui_non/
I think there is no need to speak french here (*)

or have a look what I understood you want
http://stephane.moriaux.perso.orange.fr/truc/table-opener/

(*) dictionary
ouvrir = to open ouvert = opened
fermer = to close fermé = closed
dis-moi = tell me
 

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
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top