Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Accessing objects from opened window

Reply
Thread Tools

Accessing objects from opened window

 
 
kosmodisk
Guest
Posts: n/a
 
      09-12-2006
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--------

 
Reply With Quote
 
 
 
 
ASM
Guest
Posts: n/a
 
      09-12-2006
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
 
Reply With Quote
 
 
 
 
kosmodisk
Guest
Posts: n/a
 
      09-18-2006
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
(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


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


 
Reply With Quote
 
ASM
Guest
Posts: n/a
 
      09-26-2006
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
> (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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Trouble retrieving window location from a previously opened window ? Mark Javascript 2 12-24-2005 06:34 PM
Accidentaly opened I-Bagle - and then opened virus vault ?? Morph Computer Information 2 02-01-2005 03:43 AM
Is that possible I can assign an window object variable to an already opened window datactrl Javascript 3 05-29-2004 06:52 AM
Invalid session when a new IE window is opened using window.open() raj ASP General 8 04-09-2004 06:50 AM
How to get values back from new window opened using window.open() Manjit Javascript 0 07-25-2003 01:40 AM



Advertisments