Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-06-2010, 05:36 PM   PM User | #1
mikefitz888
New to the CF scene

 
Join Date: Apr 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
mikefitz888 is an unknown quantity at this point
Question Show div within an iframe

On my page there's an iframe containing a div which I've hidden with code on the actual iframe page. I want the iframe content only to be accessible by clicking a button on the main page.
Here's the main parts of the code:

Within the iframe:

Code:
<html>
<head>
<script language="javascript">
<!--

var state = 'none';

function showhide(layer_ref) {

if (state == 'block') {
state = 'none';
}
else {
state = 'block';
}
if (document.all) { 
eval( "document.all." + layer_ref + ".style.display = state");
}
if (document.layers) { 
document.layers[layer_ref].display = state;
}
if (document.getElementById &&!document.all) {
hza = document.getElementById(layer_ref);
hza.style.display = state;
}
}
//-->
</script> 
</head>
<body onload="showhide('div')" style="display: none;">
<div id="div" name="div">
Some Content...
</div>
</body>
</html>
And on the main page:

Code:
<html>
<head>
</head>
<body>
<div id="div1">
<iframe onload="iFrameHeight()"	id="blockrandom"
	name="iframe"
	src="http://somewhere.com/"
	width="100%"
	height="500"
	scrolling="auto"
	align="top"
	frameborder="0"
	class="wrapper">
	This option will not work correctly. Unfortunately, your browser does not support inline frames.</iframe>
</div>
<div id="div2">
<input type="button" value="Show/Hide Search" onclick="document.getElementById('blockrandom').contentWindow.showhide('div')">
</div>
</body>
</html>
The page hides successfully but I can't get it to show again from the button on the main page.
If there's something wrong with my code or if there was a way that the iframe page could check if it was loaded on the right page or not would be great although i'm not sure if that's possible.

Any solutions or alternatives are welcome. Thanks.

P.S. This is on Joomla CMS, I don't think it should make a difference but correct me if I'm wrong.
mikefitz888 is offline   Reply With Quote
Old 04-06-2010, 06:25 PM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,195
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
If the IFRAME is not from the *same domain* as the main page, then you can *NOT* use JavaScript to access anything internal to the iframe, at all.

The example code you show there does
Code:
src="http://somewhere.com/"
which makes me suspicious that the iframe code is, indeed, from a different domain.

Also, the JS code you show there is *ANCIENT*. It was designed for use with MSIE 4 and Netscape 4, both of which are hopefully dead lo these many years. And it even has support for MSIE 3, in the form of the <!-- and --> crap.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is online now   Reply With Quote
Reply

Bookmarks

Tags
div, hide, iframe, joomla, show

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:45 PM.


Advertisement
Log in to turn off these ads.