/    Sign up×
Community /Pin to ProfileBookmark

Parent’s JS-style control href’s elements in Iframe?

Is it possible to control the style of a page from it’s parent with JS? Let’s say I wanted to load a page in an iframe and display:none; elements of that href from the parent page.

At best I’d like to do it by tag name.

Something like this:

[B]Parent.html[/B]

[CODE]<html><head>
<script type=”text/javascript”>
function hideIt()
{
var no = document.gotcha.href.document.getElementsByTagName(‘div’);
return ( no.style.display == “block” ? no.style.display = “none” : no.style.display = “none” );
}
</script>

</head><body>

<iframe name=”gotcha” src=”test.html” width=400 height=400></iframe>
<a href=”#” onclick=”hideIt()”>here</a>
</body></html>[/CODE]

[B]test.html[/B]

[CODE]<html><head>
</head><body>
<div>words</div>
</body></html>[/CODE]

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@Logic_AliApr 16.2007 — Perhaps like this:
[CODE]function hideIt()
{
var no = window.frames.gotcha.document.getElementsByTagName('div')[0];
no.style.display=(no.style.display == "block" ? "none" : "block" );
}[/CODE]
Copy linkTweet thisAlerts:
@bustyaauthorApr 16.2007 — Exactly what I was looking for, thanks.
×

Success!

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