/    Sign up×
Community /Pin to ProfileBookmark

Can’t acess opened window DOM

Hello everyone, i know this question may have been asked many times before but i really can’t find a solution to it!

I’m opening a new window and trying to set the visibility style for one of the child window’s buttons but it seems nothing of which i tried is working, here’s the latest code i’m trying but it won’t work

[CODE]
var newWin=window.open(“window_1.html”, “_blank”, “”);
newWin.onLoad = function() {
newWin.document.getElementById(“return”).style.visibility=”hidden”;
}
[/CODE]

what I’ve managed to get it work is to check for opener value in the child window if it doesn’t equal to null and it worked

[CODE]
//child window
function chkOpen() {
if (window.opener != null) {
document.getElementById(“return”).style.visibility=”hidden”
}
}
[/CODE]

But i really need to know if i can access a child window’s DOM from the opener code?

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@cootheadSep 16.2013 — Hi there Kaspro,

does this help...
[color=navy]
var newWin=window.open('window_1.html','_blank','');

newWin.onload=function() {
alert(this.document.documentElement.innerHTML);
alert(this.document.body.innerHTML);
}[/color]


[i]coothead[/i]
Copy linkTweet thisAlerts:
@PadonakSep 16.2013 — try this

<i>
</i>
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv="content-type" content="text/html; charset=utf-8" /&gt;
&lt;title&gt;123&lt;/title&gt;
&lt;script&gt;
var newWin;
function zz(){
try{newWin.document.getElementById("return").style.visibility="hidden";}
catch(e){setTimeout('zz()',100);}
}
window.onload=function(){
document.getElementById('wo').onclick=function(){
newWin=window.open("window_1.htm", "", "height=500,width=500,scrollbars=no,statusbar=no,menubar=no,top=100,left=100");
zz();
}
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;center&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;input type="button" id="wo" value="Open child window" /&gt;&lt;/center&gt;
&lt;/body&gt;
&lt;/html&gt;

Copy linkTweet thisAlerts:
@cootheadSep 16.2013 — Hi there Padonak,

don't you think that using....
[color=navy]
&lt;center&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;[/color]

...is a rather naughty. ?



[i]coothead[/i]
Copy linkTweet thisAlerts:
@PadonakSep 16.2013 — who cares lol ))) just was too lazy to write styles ?
Copy linkTweet thisAlerts:
@KasproauthorSep 17.2013 — try this

<i>
</i>
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv="content-type" content="text/html; charset=utf-8" /&gt;
&lt;title&gt;123&lt;/title&gt;
&lt;script&gt;
var newWin;
function zz(){
try{newWin.document.getElementById("return").style.visibility="hidden";}
catch(e){setTimeout('zz()',100);}
}
window.onload=function(){
document.getElementById('wo').onclick=function(){
newWin=window.open("window_1.htm", "", "height=500,width=500,scrollbars=no,statusbar=no,menubar=no,top=100,left=100");
zz();
}
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;center&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;input type="button" id="wo" value="Open child window" /&gt;&lt;/center&gt;
&lt;/body&gt;
&lt;/html&gt;

[/QUOTE]


Hello and sorry for late response, actually this works, so it's all about waiting for the child window to get fully loaded, right???
Copy linkTweet thisAlerts:
@PadonakSep 18.2013 — absolutely )
×

Success!

Help @Kaspro spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.4,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...