By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,636 Members | 1,190 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,636 IT Pros & Developers. It's quick & easy.

Accessing objects from opened window

P: n/a
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--------

Sep 12 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/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...i_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(\'tes t\')+"\'");'+
'\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;">
</form>
<!-- (3) after page has loaded, I can access the object -->
<input type="submit"
<input type="button"


--
Stephane Moriaux et son [moins] vieux Mac
Sep 12 '06 #2

P: n/a
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 <linkand <scriptlines from output HTML, my FF
gets the object.
alert(win.document.getElementById('test'));
// now it returns HTMLObject or something

Kosmodisk
ASM wrote:
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...i_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(\'tes t\')+"\'");'+
'\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;">
</form>
<!-- (3) after page has loaded, I can access the object -->
<input type="submit"

<input type="button"


--
Stephane Moriaux et son [moins] vieux Mac
Sep 18 '06 #3

P: n/a
ASM
kosmodisk a écrit :
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 :)
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...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.../table-opener/

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

--
ASM
Sep 26 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.