By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,713 Members | 2,012 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,713 IT Pros & Developers. It's quick & easy.

Detecting IFRAME Container

P: 42
I have a page that can be accessed either directly or by an AJAX tabs interface (courtesy jQuery). If accessed directly, I want the page's banner to be visible. If indirectly, the banner needs to be not displayed ('display:none').

If AJAX and IFRAMEs weren't involved, a containing object would be a pretty easy thing to detect. Since I'm using jQuery, though, I'm having trouble.

Any suggestions? Thanks.
Aug 2 '08 #1
Share this Question
Share on Google+
4 Replies


rohypnol
P: 54
Hello,

This should tell you if your page has loaded directly or indirectly: top == window
If the current window is on the top, it will be true. If the current window is an IFRAME, it will be false.

I think you shouldn't use JavaScript for this, but rather use jQuery or the IFRAME or whatever you're using to send an extra parameter to the page (through GET) and parse it on the server. If your page was accessed using "minimize=1" you should output it with "display:none", otherwise you shouldn't touch the display of that menu.

Regards,
Tom
Aug 2 '08 #2

rnd me
Expert 100+
P: 427
give the banner an id of banner, then
Expand|Select|Wrap|Line Numbers
  1. <script>
  2. if(location.href != top.location.href){ document.getElementById("banner").style.display="none"
  3. </script>
  4.  
  5.  
Aug 4 '08 #3

P: 42
Hello,

This should tell you if your page has loaded directly or indirectly: top == window
If the current window is on the top, it will be true. If the current window is an IFRAME, it will be false.

I think you shouldn't use JavaScript for this, but rather use jQuery or the IFRAME or whatever you're using to send an extra parameter to the page (through GET) and parse it on the server. If your page was accessed using "minimize=1" you should output it with "display:none", otherwise you shouldn't touch the display of that menu.

Regards,
Tom
This is actually a very good idea. It just requires an extra minute of effort to get working in the CodeIgniter PHP framework. Something like this in the controller:

Expand|Select|Wrap|Line Numbers
  1. function myTabsPage($banner) // '1' as URL parameter automatically put in $banner
  2. {
  3.     $data['display'] = $banner == 1 ? 'none' : 'block';
  4.  
  5.     $this -> load -> view('myView', $data);
  6. }
  7.  
And then...

Expand|Select|Wrap|Line Numbers
  1. <div id="banner" style="display:<?= $display ?>">awsum banner go here, lolz</div>
  2.  
Thanks, I'll definitely consider this.
Aug 4 '08 #4

P: 1
You have been helpful ... I needed this to know how to go about manipulating things on my code. Now I know ...

Many thanks

give the banner an id of banner, then
Expand|Select|Wrap|Line Numbers
  1. <script>
  2. if(location.href != top.location.href){ document.getElementById("banner").style.display="none"
  3. </script>
  4.  
  5.  
Nov 21 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.