PDA

View Full Version : close button inside iframe / manage iframe


RationalRabbit
11-14-2007, 02:44 AM
Hi!
My page has a list of products. Clicking on one of these product images brings up a detailed information iframe "popup" with interactive photos and text. The information is stored in a MySQL database, accessed with PHP.

I've struggled for hours to find the best way to open and close this iframe. The below method works, but is slow. I'm wondering if there is a way to do this that will pop up the iframe with its content faster.

Parent Page Head:

function OpenFrame(ID)
{
newID = ID;
var makeframe=document.createElement("iframe");
makeframe.setAttribute("id", "PopIframe");
makeframe.setAttribute("class", "PopIframe");
makeframe.setAttribute("name", "PopIframe");
makeframe.setAttribute("frameborder", "0");
makeframe.setAttribute("src", "detailbox.php?ID=" + newID); // ID=Database record ID for item search
makeframe.setAttribute("scrolling", "no");
document.body.appendChild(makeframe);
}

function ClosePopup()
{
var ifr = parent.document.getElementById("PopIframe");
ifr.parentNode.removeChild(ifr);
}


detailbox.php:
<a class="CloseLink" href="javascript:void(0);" onclick="window.parent.ClosePopup();">X</a>


These products each have a series of styles, so once detailbox.php is open, the user may select other product information in the series by selecting an image, which recalls the page in the iframe with a different database record ID.

Currently, on my computer, with a good broadband connection, this takes about 3 seconds for a page to load in the iframe. I'm hoping there is some way to make it snappier.

shyam
11-14-2007, 12:53 PM
try using onclick="top.ClosePopup()"

RationalRabbit
11-15-2007, 12:22 AM
Shyam -

Thanks for the reply. But the problem is in the load. This can be somewhat solved by not recreating the wheel (translate "iframe") every time, and simply hiding the iframe. The problem there is when it is un-hidden, the last contents are still in memory and appear first. I can't seem to get around that. That is why I an completely destroying, then recreating the iframe, which, of course, is time consuming on opening the frame.

sotn0r
01-22-2008, 09:54 AM
did you try setting the src of the iframe to about:blank before showing it ?