/    Sign up×
Community /Pin to ProfileBookmark

MM_showHideLayers to hide an iFrame

I have in my HTML/CSS an iFrame that is hidden by default. You click a link to make it visible using MM_showHideLayers. What I need to do is make a link work from within that iFrame that makes it hidden again. Any takers?

Thanks – Chris B.

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@KorDec 04.2009 —  using MM_showHideLayers. [/QUOTE]
Using [I]what[/I]? Do you think we all know what a [B]M[/B]ickey[B]M[/B]ouse (MM = former MacroMedia - now Adobe) DreamWeaver generated function might look like? :rolleyes:

My advice is to learn JavaScript and write your own codes. Don't let any editor to do that: it will make it clumsy, unreadable and redundant. And not always cross-browser.
Copy linkTweet thisAlerts:
@tomorrows_hereauthorDec 04.2009 — I looked through other forums and everyone referred to that script seemed to all be familiar with it, so I guess I kind of assumed. Sorry about that. Obviously I couldn't find an answer so I posted my question on this board.

Basically my question boils down to this: Can I, maybe using a target method or something, have a link in an iFrame inside a page call a script from the parent HTML document?
Copy linkTweet thisAlerts:
@KorDec 04.2009 — I looked through other forums and everyone referred to that script seemed to all be familiar with it[/quote]
I doubt.

Basically my question boils down to this: Can I, maybe using a target method or something, have a link in an iFrame inside a page call a script from the parent HTML document?[/QUOTE]

My answer is YES. [B]parent[/B] is the referrer, seen from an iframe. [B]IF[/B] both the parent and the iframe loaded page belong to the same domain.

Give us more details.
Copy linkTweet thisAlerts:
@jamesbcox1980Dec 04.2009 — You simply need to access the "top" window. As long as your iframe is on the same domain, this will not be difficult. But you'll not be able to use MM_showHideLayers() because of the way functions, element referencing, and browser security work.

What MM_showHideLayers() actually does, since Kor pointed out that not everyone knows the structure of it, is to change the style property "visibility" to either "visible" or "hidden". This will literally hide the iframe, but it will not collapse. In effect, you'll have a big block of whitespace where the iFrame is hidden.

Nevertheless, we simply need to perform the same function as MM_showHideLayers(). Since we don't need to toggle the show/hide text in the iframe (because it's hidden), all we have to do is create a link that will do the hiding:

[code=html]
<a href="#" onclick="top.document.getElementById('myIframe').style.visibility='hidden'; return false;">Hide</a>
[/code]


"top" refers to the top window, and is similar to saying "window". You can also say "parent", but that all depends on how many nested frames you're using.


--------
That's that, and here's something to consider:

You could also adjust MM_showHideLayers() to use "display" instead if you want to make it collapse the iFrame:

[CODE]
//This is from a legacy script, so it might be different from the version you're using
//Also, I cleaned it up a little cause Dreamweaver scripts suck.
function MM_showHideLayers() {
var i, visStr, obj, args = arguments;
for (i = 0; i < (args.length - 2); i += 3) {
//This function also apparently requires the findObj() function so keep that in mind
if ((obj = findObj(args[i])) !== null) {
visStr = args[i + 2];
if (obj.style) {
obj = obj.style;
if (visStr === 'show') {
visStr = 'block';
}
else if (visStr === 'hide') {
visStr = 'none';
}
}
obj.display = visStr;
}
}
}
[/CODE]


Off subject (and to continue on what Kor said)... You know I never really knew how messy, inconsistent, and slow DW scriptlets are. I haven't ever used them because I've always programmed my own functions. I think the problem with using someone else's re-useable UDFs is that you might not realize how much work you're making the JS engine do just to get a simple thing from a function! (consequently, I prettied up the DW function above a little).

I agree with Kor, you really should learn some more javascript and program your own functions.
×

Success!

Help @tomorrows_here 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 6.1,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...