Detecting IFRAME Container

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • spamguy
    New Member
    • Sep 2007
    • 42

    Detecting IFRAME Container

    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.
  • rohypnol
    New Member
    • Dec 2007
    • 54

    #2
    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:no ne", otherwise you shouldn't touch the display of that menu.

    Regards,
    Tom

    Comment

    • rnd me
      Recognized Expert Contributor
      • Jun 2007
      • 427

      #3
      give the banner an id of banner, then
      Code:
      <script>
      if(location.href != top.location.href){ document.getElementById("banner").style.display="none"
      </script>

      Comment

      • spamguy
        New Member
        • Sep 2007
        • 42

        #4
        Originally posted by rohypnol
        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:no ne", 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:

        [code=php]
        function myTabsPage($ban ner) // '1' as URL parameter automatically put in $banner
        {
        $data['display'] = $banner == 1 ? 'none' : 'block';

        $this -> load -> view('myView', $data);
        }
        [/code]

        And then...

        [code=html]
        <div id="banner" style="display: <?= $display ?>">awsum banner go here, lolz</div>
        [/code]

        Thanks, I'll definitely consider this.

        Comment

        • willowdan
          New Member
          • Nov 2008
          • 1

          #5
          You have been helpful ... I needed this to know how to go about manipulating things on my code. Now I know ...

          Many thanks

          Originally posted by rnd me
          give the banner an id of banner, then
          Code:
          <script>
          if(location.href != top.location.href){ document.getElementById("banner").style.display="none"
          </script>

          Comment

          Working...