Can iframe hide itself?

N

Noozer

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!
 
T

Travis Newbury

Noozer said:
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.
 
N

Noozer

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?
 
N

Noozer

Noozer said:
how


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.
 
T

Travis Newbury

Noozer said:
... 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
 
T

Travis Newbury

Noozer said:
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!
 
C

coolsti

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
 
Joined
Oct 20, 2006
Messages
1
Reaction score
0
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,008
Latest member
HaroldDark

Latest Threads

Top