/    Sign up×
Community /Pin to ProfileBookmark

Accessing the Parent Frame

I’m trying to figure out why this code isn’t working. I’m using an iframe and I have this code in the src file for that iframe.

[code=html]
if (parent.location == “http://domain.com/store.html”){
document.write(“********************************”);
}
[/code]

What really is throwing me off is that if I put in a redirect statement like:

[code=html]
parent.location = “http://domain.com”;
[/code]

That works fine.

I’ve tried self.parent.location, I’ve tried parent.window.location, I’ve tried parent.location.href, none of it works.

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@Sterling_IsfineNov 11.2010 — 
[code=html]
if (parent.location == "http://domain.com/store.html"){
document.write("********************************");
}
[/code]

[/QUOTE]
Do you have a querystring in your URL?

[I]parent.location[/I] or more correctly [I]parent.location.href[/I] must match "http://domain.com/store.html" exactly.

Try alerting [I]parent.location.href[/I]

Try:[CODE]if ( parent.location.href.indexOf( "http://domain.com/store.html") == 0 ){
document.write("********************************");
}[/CODE]
Copy linkTweet thisAlerts:
@empireapathyauthorNov 11.2010 — Did an alert:

alert(parent.location.href);

It came up "undefined".
Copy linkTweet thisAlerts:
@Sterling_IsfineNov 11.2010 — Did an alert:

alert(parent.location.href);

It came up "undefined".[/QUOTE]
I can't think of a scenario in which that could happen. Do you have a URL?
×

Success!

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