PDA

View Full Version : Iframe Reloading when display=none


onlyican
05-12-2008, 09:16 AM
Hello

I am having some trouble with a script.

I have drilled down the code and still get this issue.

When I HIDE the iframe using javascript, the iframe reloads
I can not use SHOW / HIDE div as The iframe will be running MSSQL queries.

I put an ALERT in the iframe and found it shows when the iframe is hidden (IN FF 2 and 3 only)

Here is the basics of the code

MAIN PAGE

<script type='text/javascript'>
function OpenIframe(){
document.getElementById("MyIframe").style.display="block";
document.getElementById("MyIframe").src = "test_iframe.asp";
}
</script>

<iframe id='MyIframe' src='' style='display:none;'></iframe>

<a href='#' onclick='OpenIframe();'>Open IFrame</a>


IFRAME CODE


<script type='text/javascript'>
alert("The Iframe has loaded");

function CloseIframe(){
parent.document.getElementById("MyIframe").src = "";
parent.document.getElementById("MyIframe").style.display = "none";

}

</script>

<a href='#' onclick='CloseIframe();'>Close Iframe</a>


So when the user clicks the iframe, it shows, alert message appears.
When I click CLOSE IFRAME, it hides, but the alert message appears again.

Can anyone help please.

Thanks in advance.

onlyican
05-12-2008, 10:11 AM
I have got the solution.

Put a return false on the close iframe link

<a href='#' onclick='CloseIframe(); return false;'>Close Iframe</a>