/    Sign up×
Community /Pin to ProfileBookmark

Reference cookie in iframes on the same domain

I have a parent page that has 2 iframes on it. I set a cookie on the parent page. I need to access that cookie in each of the iframes. The iframes are on the same domain as the parent. The iframes have id’s of “searchresults” and “games”.

Based on what the cookie is set to (“thumbnail” or “textlist” view) the content <div>’s will be displayed or turned off.

//If the listview equals thumbnail then display the thumbnail view <div>
var whatisit = top.getCookie(“listview”);
alert(“is this my cookie = “+getCookie(“listview”));
alert(“is this my cookie2 = “+whatisit);

if (top.document.getCookie(“listview”) == “thumbnail”) {
[INDENT]//top.frames[‘searchresults’].document.getElementById(‘videolist’).style.display=’none’;
top.frames[‘searchresults’].document.getElementById(‘videolist2′).style.display=’block’;[/INDENT]
}

I believe my problem is that I’m not referencing the document object correctly to refer to the cookie. When writing an alert of the cookie from the iframe I get “undefined” as the message instead of the cookie value.

Thanks in advance.

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@Arty_EffemDec 28.2006 — The iframes have id's of "searchresults" and "games".[/QUOTE]Use the [I]name[/I] attribute instead.
×

Success!

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