hide/show an iframe ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mel

    #1

    hide/show an iframe ?

    i need to have 2 side by side iframes, a link on top of the one will
    show/hide the other

    can someone help me pleeeeezzzzz ?


  • Martin Honnen

    #2
    Re: hide/show an iframe ?



    Mel wrote:
    [color=blue]
    > i need to have 2 side by side iframes, a link on top of the one will
    > show/hide the other[/color]

    An <iframe> element is an element like others, you can (in browsers like
    IE 5+, Netscape 6+, Opera 7+) change its CSS display property e.g.
    <iframe id="iframe1" src="whatever.h tml" ...></iframe>

    function hideElement (element) {
    if (element.style) {
    element.style.d isplay = 'none';
    }
    }

    function showElement (element) {
    if (element.style) {
    element.style.d isplay = '';
    }
    }

    var iframe;
    if (document.getEl ementById && (iframe =
    document.getEle mentById('ifram e1'))) {
    hideElement(ifr ame);
    }

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/

    Comment

    • Mel

      #3
      Re: hide/show an iframe ?

      i tried:
      <iframe id="ME" src="http://www.yahoo.com" frameborder=1></iframe>

      <script>
      function hideElement (element) {
      if (element.style) {
      element.style.d isplay = 'none';
      }
      }

      function showElement (element) {
      if (element.style) {
      element.style.d isplay = '';
      }
      }

      var iframe;
      if (document.getEl ementById && (iframe = document.getEle mentById('ME')) ) {
      showElement(ifr ame);
      }

      </script>

      <BR><BR>
      <a href="#" onclick="javasc ript:hideElemen t('ME')">XXXXXX XXXXXX</a><BR><BR>

      when i click on the link, the iframe will not hide, can you please help me ?

      thanks a lot


      "Martin Honnen" <mahotrash@yaho o.de> wrote in message
      news:423eddca$0 $11475$9b4e6d93 @newsread2.arco r-online.net...[color=blue]
      >
      >
      > Mel wrote:
      >[color=green]
      > > i need to have 2 side by side iframes, a link on top of the one will
      > > show/hide the other[/color]
      >
      > An <iframe> element is an element like others, you can (in browsers like
      > IE 5+, Netscape 6+, Opera 7+) change its CSS display property e.g.
      > <iframe id="iframe1" src="whatever.h tml" ...></iframe>
      >
      > function hideElement (element) {
      > if (element.style) {
      > element.style.d isplay = 'none';
      > }
      > }
      >
      > function showElement (element) {
      > if (element.style) {
      > element.style.d isplay = '';
      > }
      > }
      >
      > var iframe;
      > if (document.getEl ementById && (iframe =
      > document.getEle mentById('ifram e1'))) {
      > hideElement(ifr ame);
      > }
      >
      > --
      >
      > Martin Honnen
      > http://JavaScript.FAQTs.com/[/color]


      Comment

      • Martin Honnen

        #4
        Re: hide/show an iframe ?



        Mel wrote:
        [color=blue]
        > i tried:
        > <iframe id="ME" src="http://www.yahoo.com" frameborder=1></iframe>
        >
        > <script>
        > function hideElement (element) {
        > if (element.style) {
        > element.style.d isplay = 'none';
        > }
        > }
        >
        > function showElement (element) {
        > if (element.style) {
        > element.style.d isplay = '';
        > }
        > }
        >[/color]
        [color=blue]
        > </script>[/color]

        [color=blue]
        > <a href="#" onclick="javasc ript:hideElemen t('ME')">XXXXXX XXXXXX</a>[/color]

        You need to find the right element object of course as the code above showed
        <a href="#"
        onclick="var iframe;
        if (document.getEl ementById) {
        iframe = document.getEle mentById('ME');
        }
        if (iframe) {
        hideElement(ifr ame);
        }
        return false;">...</a>
        --

        Martin Honnen
        http://JavaScript.FAQTs.com/

        Comment

        • Mel

          #5
          Re: hide/show an iframe ?

          thanks a lot for your help. it works fine.

          sorry for the next question, but i am a newbeee

          i need my link to display "show" when the iframe is hidden and "hide" when
          it is visible. i struggled with it for while and now i have "given up :-)"

          if its not a bother, can you put me on the right path ?

          thanks again

          "Martin Honnen" <mahotrash@yaho o.de> wrote in message
          news:423ee72b$0 $11476$9b4e6d93 @newsread2.arco r-online.net...[color=blue]
          >
          >
          > Mel wrote:
          >[color=green]
          > > i tried:
          > > <iframe id="ME" src="http://www.yahoo.com" frameborder=1></iframe>
          > >
          > > <script>
          > > function hideElement (element) {
          > > if (element.style) {
          > > element.style.d isplay = 'none';
          > > }
          > > }
          > >
          > > function showElement (element) {
          > > if (element.style) {
          > > element.style.d isplay = '';
          > > }
          > > }
          > >[/color]
          >[color=green]
          > > </script>[/color]
          >
          >[color=green]
          > > <a href="#" onclick="javasc ript:hideElemen t('ME')">XXXXXX XXXXXX</a>[/color]
          >
          > You need to find the right element object of course as the code above[/color]
          showed[color=blue]
          > <a href="#"
          > onclick="var iframe;
          > if (document.getEl ementById) {
          > iframe = document.getEle mentById('ME');
          > }
          > if (iframe) {
          > hideElement(ifr ame);
          > }
          > return false;">...</a>
          > --
          >
          > Martin Honnen
          > http://JavaScript.FAQTs.com/[/color]


          Comment

          • c.anandkumar@gmail.com

            #6
            Re: hide/show an iframe ?

            Mel wrote:[color=blue]
            > thanks a lot for your help. it works fine.
            >
            > sorry for the next question, but i am a newbeee
            >
            > i need my link to display "show" when the iframe is hidden and "hide"[/color]
            when[color=blue]
            > it is visible.[/color]
            Have a span surrounding the anchor text that you would like to change.

            <a href="javascrip t:HideFrame()"> Hide Frame</a>

            now becomes

            <span id="sFrameAncho r"><a href="javascrip t:HideFrame()"> Hide
            Frame</a></span>

            and
            <script language="Javas cript">
            function HideFrame()
            {
            var obj = document.getEle mentById ('sFrameAnchor' );
            obj.innerHTML = '<a href="javascrip t:ShowFrame()"> Show Frame</a>';
            // Set the frame as invisible here - you have the code to do so
            return;
            }
            function ShowFrame()
            {
            var obj = document.getEle mentById ('sFrameAnchor' );
            obj.innerHTML = '<a href="javascrip t:HideFrame()"> Hide Frame</a>';
            // Set the frame as visible here - you have the code to do so
            return;
            }
            </script>[color=blue]
            > i struggled with it for while and now i have "given up :-)"
            >
            > if its not a bother, can you put me on the right path ?
            >
            > thanks again
            >
            > "Martin Honnen" <mahotrash@yaho o.de> wrote in message
            > news:423ee72b$0 $11476$9b4e6d93 @newsread2.arco r-online.net...[color=green]
            > >
            > >
            > > Mel wrote:
            > >[color=darkred]
            > > > i tried:
            > > > <iframe id="ME" src="http://www.yahoo.com"[/color][/color][/color]
            frameborder=1></iframe>[color=blue][color=green][color=darkred]
            > > >
            > > > <script>
            > > > function hideElement (element) {
            > > > if (element.style) {
            > > > element.style.d isplay = 'none';
            > > > }
            > > > }
            > > >
            > > > function showElement (element) {
            > > > if (element.style) {
            > > > element.style.d isplay = '';
            > > > }
            > > > }
            > > >[/color]
            > >[color=darkred]
            > > > </script>[/color]
            > >
            > >[color=darkred]
            > > > <a href="#"[/color][/color][/color]
            onclick="javasc ript:hideElemen t('ME')">XXXXXX XXXXXX</a>[color=blue][color=green]
            > >
            > > You need to find the right element object of course as the code[/color][/color]
            above[color=blue]
            > showed[color=green]
            > > <a href="#"
            > > onclick="var iframe;
            > > if (document.getEl ementById) {
            > > iframe = document.getEle mentById('ME');
            > > }
            > > if (iframe) {
            > > hideElement(ifr ame);
            > > }
            > > return false;">...</a>
            > > --
            > >
            > > Martin Honnen
            > > http://JavaScript.FAQTs.com/[/color][/color]

            Comment

            Working...