/    Sign up×
Community /Pin to ProfileBookmark

identifying parent/child window

Hi all. I’m using a script to open a child window and building the content by pulling the head and a particular div from the parent window. There are scripts embedded within the div section that must run only in the parent window, not the child window. So, a simple statement is needed that basically says “if this script loads into a child window, don’t run it. If it’s loaded into a parent window, run it”. What I don’t know is how to identify the child window as a child. I can give the window a name when I open it, but how do I access that name in my script (like window.name or something…). Any info would be appreciated, thanks.

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@JonaOct 24.2003 — [i]Parent[/i]

[font=monospace]

<script type="text/javascript"><!--

var child = window.open("child_window.html","child","width=200,height=300");

function alertSomething(something){

alert(something);

}

//--></script>

[/font]

[i]Child (popup)[/i]

[font=monospace]

<script type="text/javascript"><!--

opener.alertSomething("I am an open child");

//--></script>

[/font]

[b][J]ona[/b]
×

Success!

Help @ocbazgi 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.18,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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