Can iframe hide itself?

Discussion in 'HTML' started by Noozer, May 25, 2005.

  1. Noozer

    Noozer Guest

    I have an IFRAME (yes I know that frames are evil) that is made visible when
    the user needs to edit some values in a database. Once the user had
    completed the edit, or cancels the edit, I would like the IFRAME to become
    invisible again. The reason for the iframe is that this ASP page contains a
    rather large SQL query that we would avoid rerunning when the user edits
    some data.

    It's easy to make the frame visible as this code is included in the parent
    document, but the code to hide the IFRAME again will be in the IFRAME
    document. How can the child IFRAME hide itself? Or, in other words, how can
    the child IFRAME reference the parent document to change it's style?

    Thx!
    Noozer, May 25, 2005
    #1
    1. Advertising

  2. Noozer wrote:
    > It's easy to make the frame visible as this code is included in the parent
    > document, but the code to hide the IFRAME again will be in the IFRAME
    > document. How can the child IFRAME hide itself? Or, in other words, how can
    > the child IFRAME reference the parent document to change it's style?
    >


    parent.iframeID.style Using the right syntax of course.

    --
    -=tn=-
    Travis Newbury, May 25, 2005
    #2
    1. Advertising

  3. Noozer wrote:

    > I have an IFRAME (yes I know that frames are evil)


    I sense the presence of a basis for cognitive dissonance,
    there... ;)

    --
    Blinky Linux Registered User 297263
    Killing all Usenet posts from Google Groups
    Info: http://blinkynet.net/comp/uip5.html
    Blinky the Shark, May 25, 2005
    #3
  4. Noozer

    Noozer Guest

    "Travis Newbury" <> wrote in message
    news:1Z3le.11345$...
    > Noozer wrote:
    > > It's easy to make the frame visible as this code is included in the

    parent
    > > document, but the code to hide the IFRAME again will be in the IFRAME
    > > document. How can the child IFRAME hide itself? Or, in other words, how

    can
    > > the child IFRAME reference the parent document to change it's style?


    > parent.iframeID.style Using the right syntax of course.


    Hrm.. For some reason it doesn't seem to work...

    Iframe from the parent page:

    <iframe src="subEdit.asp" name="EditFrame" id="EditFrame"
    style="display:block;"></iframe>

    ....and this javascript from the iframe page will show the name "EditFrame":
    alert (parent.EditFrame.name);

    ....but this javascript from the iframe page causes an error:
    parent.EditFrame.style.display="none";

    .... the error being "Parent.EditFrame.style is not an object"

    *sigh* What am I doing wrong?
    Noozer, May 25, 2005
    #4
  5. Noozer

    Noozer Guest

    "Noozer" <> wrote in message
    news:Jp5le.1482139$8l.1466726@pd7tw1no...
    > "Travis Newbury" <> wrote in message
    > news:1Z3le.11345$...
    > > Noozer wrote:
    > > > It's easy to make the frame visible as this code is included in the

    > parent
    > > > document, but the code to hide the IFRAME again will be in the IFRAME
    > > > document. How can the child IFRAME hide itself? Or, in other words,

    how
    > can
    > > > the child IFRAME reference the parent document to change it's style?

    >
    > > parent.iframeID.style Using the right syntax of course.

    >
    > Hrm.. For some reason it doesn't seem to work...
    >
    > Iframe from the parent page:
    >
    > <iframe src="subEdit.asp" name="EditFrame" id="EditFrame"
    > style="display:block;"></iframe>
    >
    > ...and this javascript from the iframe page will show the name

    "EditFrame":
    > alert (parent.EditFrame.name);
    >
    > ...but this javascript from the iframe page causes an error:
    > parent.EditFrame.style.display="none";
    >
    > ... the error being "Parent.EditFrame.style is not an object"
    >
    > *sigh* What am I doing wrong?


    ARGH! IFRAMEs don't have a style object...

    Put the IFRAME within a SPAN and I have no problems making the SPAN
    disappear.
    Noozer, May 25, 2005
    #5
  6. Noozer wrote:

    > ... the error being "Parent.EditFrame.style is not an object"
    >
    > *sigh* What am I doing wrong?


    try replacing "parent" with "top"

    Also google "call javascript function in parent frame iframe" it has a
    of of samples

    --
    -=tn=-
    Travis Newbury, May 25, 2005
    #6
  7. Noozer wrote:
    > ARGH! IFRAMEs don't have a style object...
    > Put the IFRAME within a SPAN and I have no problems making the SPAN
    > disappear.


    If it works, the it is a solution!

    --
    -=tn=-
    Travis Newbury, May 25, 2005
    #7
  8. Noozer

    coolsti Guest

    On Wed, 25 May 2005 16:30:24 +0000, Noozer wrote:

    > I have an IFRAME (yes I know that frames are evil) that is made visible
    > when the user needs to edit some values in a database. Once the user had
    > completed the edit, or cancels the edit, I would like the IFRAME to
    > become invisible again. The reason for the iframe is that this ASP page
    > contains a rather large SQL query that we would avoid rerunning when the
    > user edits some data.
    >
    > It's easy to make the frame visible as this code is included in the
    > parent document, but the code to hide the IFRAME again will be in the
    > IFRAME document. How can the child IFRAME hide itself? Or, in other
    > words, how can the child IFRAME reference the parent document to change
    > it's style?
    >
    > Thx!


    Don't know if this helps much, but I use iframes a lot to carry out behind
    the scenes database queries. For example, if I have a select list which is
    dependent on what the user types into other fields (like a database search
    filter), I would like to perform the database query and refill the select
    list without needing to refresh the entire page. Another example is when I
    have users save data to the database. In this case, a page refresh is
    expensive due to the complexity of the page, and so an iframe to perform a
    behind-the-scenes database query (insert or update here) is perfect.

    But in my case, I define the iframe as invisible, and I leave it
    invisible. The iframe is defined with

    <div style="visibility:hidden"><iframe src="ifrm.php" name="ifrm"
    id="ifrm" scrolling="no" frameborder="0" width="0"
    height="0"></iframe></div>

    and simply calls a server side php file called ifrm.php when the iframe is
    submitted.

    The iframe itself (defined in ifrm.php) is a simple document containing a
    form and various hidden fields for data transfer. Here is part of it:

    <form name="ifrmform" method="post"
    action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <input type="hidden" name="param1" value="">
    <input type="hidden" name="param2" value="" > <input type="hidden"
    name="param3" value="" > <input type="hidden" name="param4" value="" >
    <input type="hidden" name="param5" value="" > <input type="hidden"
    name="param6" value="" > <input type="hidden" name="action" value="" >
    </form>

    So when the user fills out fields and clicks on a submit button, this
    calls a javascript which fills the iframes hidden fields from the main
    window fields, and submits the iframe. The rest of the ifrm.php code then
    does the query and spits itself out again. The new ifrm.php output
    contains javascript that fills up the main window fields or select lists
    with the database query results.

    The point is, you don't have to hide and unhide the iframe, just leave it
    hidden all the time. You can also hide the other input fields in a similar
    way if you like, using span or div tags.

    Anyway, this is an excellant excuse for the use of iframes. Behind the
    scenes database queries can be made without disrupting the user's view of
    the rest of the page.

    - steve
    coolsti, May 26, 2005
    #8
  9. Noozer

    Alain

    Joined:
    Oct 20, 2006
    Messages:
    1
    I'm late but I think I have a solution that could be of some help for other people.
    I you give an id to the iframe, say 'myframeId' try :

    parent.document.getElementById('myframeId').style.display='none'

    I have something similar working for both IE & firefox
    Alain, Oct 20, 2006
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Daedalous
    Replies:
    3
    Views:
    658
    Daedalous
    Jan 16, 2004
  2. Ryh
    Replies:
    3
    Views:
    356
  3. Mel

    hide/show an iframe ?

    Mel, Mar 21, 2005, in forum: Javascript
    Replies:
    5
    Views:
    523
  4. Bubu
    Replies:
    3
    Views:
    161
  5. Prasad
    Replies:
    2
    Views:
    112
    Prasad
    Nov 7, 2006
Loading...

Share This Page