Large_Farva
asked on
hide div if within iframe
Need to hide just one div on a page if it is displayed within an iframe. Based on other posts, this is what I came up with but it does not work.
This is my iframe:
and the script, placed just above closing body tag in the parent page:
"orange" is my div in the child I am trying to hide.
I appreciate your taking a look!
This is my iframe:
<iframe id="dash" name="dash" class="dash" src="http://www.mydomain.com" width="950" height="1000">
<p>Your browser does not support iframes.</p>
</iframe>
and the script, placed just above closing body tag in the parent page:
<script type="text/javascript">window.frames[dash].document.getElementById("orange").style.display = "none";</script>
"orange" is my div in the child I am trying to hide.
I appreciate your taking a look!
Hello bro!
Found one more thing that might help you
That you can call IFRAME load event also like below:
For more detail you can browse the link below that have DEMO too.
http://www.liveintensely.com/2010/03/jquery-and-frames/
But If you want to DOCUMENT.ONLOAD means client side page load event then you can use the following function:
But remember this will require to add JQuery.js file that I mentioned in my previous post.
Regards,
Asif Ahmed Khan
Found one more thing that might help you
That you can call IFRAME load event also like below:
$(‘#frame2').load( function()
{
});
For more detail you can browse the link below that have DEMO too.
http://www.liveintensely.com/2010/03/jquery-and-frames/
But If you want to DOCUMENT.ONLOAD means client side page load event then you can use the following function:
$(document).ready(function()
{
// For Example you want to hide your DIV after complete page load the add your code or call
funcation here in this area
$('#dash').contents().find('#orange').hide();
});
But remember this will require to add JQuery.js file that I mentioned in my previous post.
Regards,
Asif Ahmed Khan
ASKER
Tried both methods. I already have a jquery.js file in head so I did not download the other.
for the first method, I put this in the parent page just above the closing body tag..is this the right place?
For the second, I put in same place this:
Maybe I have my locations wrong...does the code go in the parent or child page...and where on the page, just to be clear (i obviously know nothing about jscript)?
for the first method, I put this in the parent page just above the closing body tag..is this the right place?
<script type='text/javascript'>$('#dash').contents().find('#orange').hide();</script>
For the second, I put in same place this:
<script type='text/javascript'>
$(‘#dash').load( function()
{
$('#dash').contents().find('#orange').hide();
});
</script>
Maybe I have my locations wrong...does the code go in the parent or child page...and where on the page, just to be clear (i obviously know nothing about jscript)?
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Thanks!
Hope this will solve your problem. Just add "JQuery" JS file in <head></head> section. If you did not use ever JQuery then you can download it from the following location or just browse the link and save as ".js",
Open in new window
Include above mentioned JAVASCRIPT file in head area and in JAVASCRIPT where you want to hide that div from IFRAME write the following code.
Open in new window
How to access iframe in jQuery
Assuming you have
Open in new window
Iframe contains div with id=”someID”:
Open in new window
Need get div’s text?
Open in new window
OR want to hide:
Open in new window
Thats all from my side hope this will help you to solve your problem.
Regards,
Asif Ahmed Khan