onOpen question

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

onOpen question

bmccune
Ok so I want to hide 2 div's when shadow box opens. The reason being that if someone comes to the site with javascript disabled I want them to click on the link and get a page with the header and footer. But if someone with javascript comes to the site I want that same link to open a shadowbox frame and hide that header and footer.

Using onOpen I can get the function to run but is there any way to target the shadowbox iFrame.

Using
        document.getElementById('header').style.display = 'none';
        document.getElementById('footer').style.display = 'none';

simply hides the homepage header and footer not the one that opens in the shadowbox. On open would be great to use or is there some way to check from within the page thats loading if it is inside a shadowbox or not. Thanks guys and Wizzud your still rockin this page. Thanks for all the help!
Reply | Threaded
Open this post in threaded view
|

Re: onOpen question

Wizzud
You are talking about a Shadowbox iframe so you must be opening Page B into an iframe from a link on Page A.
Then it's Page B that you want to suppress the header/footer of?
Why can't you simply put some javascript on Page B that sets header/footer to display:none.
If the User has javascript turned off then they will see the entire Page B page.
Any User with javascript enabled will see Page B minus header/footer. The only problem you may then have is if there is another route to Page B (for javascript-enabled Users) that does not end up with Page B being shown in a Shadowbox iframe.
Combine literacy with curiosity and a whole world of information opens up to you
Reply | Threaded
Open this post in threaded view
|

Re: onOpen question

bmccune
First yes that is what I'm doing exactly. I have the javascript setting display to none right now. But the delema as you pointed out is that if they come to the page via a direct link or some other means (search engine) it won't show the header or footer.

Is there any way to check a child css element or run the javascript as the shadowbox loads? The ideal situation would be to simply run the display none in shadowbox somehow but I've tried onOpen and that just hides the parent headers....I've tried putting it in the shadowbox.open function but it's not picking up the child elements.

Thanks again!
Reply | Threaded
Open this post in threaded view
|

Re: onOpen question

Thijs
I'm not 100% on this, but i think you can check your window's parent via JS?
Reply | Threaded
Open this post in threaded view
|

Re: onOpen question

bmccune
function parentExists()
{
 return (parent.location == window.location)? false : true;
}
if(parentExists()){
        document.getElementById('header').style.display = 'none';
        document.getElementById('footer').style.display = 'none';
}


im going to give this a go. I'll let you guys know if it works out like I'm hoping.
Reply | Threaded
Open this post in threaded view
|

Re: onOpen question

Wizzud
That would also have been my next suggestion, but with an additional check...

function removeHdFt(){
  return (window.parent.location != window.location && !!window.parent._openInMyShadowbox);
}
etc

...and in your own parent page...

<script type='text/css'> //don't need to use any callbacks to toggle this value unless you are also going to open a page //in a non-Shadowbox iframe and want the opened page's header/footer to BE shown! //the likelihood of same variable, same scope, being declared an any other page is quite low var _openInMyShadowbox = true; .... .... </script>
I believe some search engines will initially display a page framed. In fact, anybody could display the page in a frame. If you only want the header/footer to be removed when you bring up the page in your Shadowbox then there really needs to be something on your calling page to identify itself.
Combine literacy with curiosity and a whole world of information opens up to you
Reply | Threaded
Open this post in threaded view
|

Re: onOpen question

bmccune
Ok for those who might be interested in this script here is the final code that Works great!

This goes on your opener page:

<script type="text/javascript"> var _openInMyShadowbox = true; </script> 

This goes on your iframe page:

<script type="text/javascript"> function removeHdFt(){ return (window.parent.location != window.location && !!window.parent._openInMyShadowbox)? false : true; } if(!removeHdFt()){ document.getElementById('header').style.display = 'none'; document.getElementById('footer').style.display = 'none'; } }); </script>
Reply | Threaded
Open this post in threaded view
|

Re: onOpen question

bmccune
Oh and thanks to Wizzud and Thijs very cool!