/    Sign up×
Community /Pin to ProfileBookmark

finding the parent of an iframe

hello everyone.
I want to traverse all the way up to the parent of all the iframes in my page.
When i use
<script laguage=”javascript”>
par=window.location;
ch=parent.par;
document.write(ch);
</script>

it will print out the parent. However when run within an iframe, it will just print out “undefined”.

Ex: page1 has the script in it
page2 has an <iframe src=”page1.html”>
page3 has an <iframe src=”page2.html”>

when on page1.html it prints correctly. When on page2.html or page3.html it will print out undefined.

What is the matter?

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@gil_davisJun 24.2008 — To get "all the way up", use window.top.

Using document.write() in a function like that will wipe out the document. Until you know what you are doing, use alert() instead.
Copy linkTweet thisAlerts:
@asgardauthorJun 24.2008 — thanks so much!
×

Success!

Help @asgard 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,
)...