User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 456,234 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,754 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 2042 | Replies: 5
Reply
Join Date: Nov 2007
Posts: 2
Reputation: RationalRabbit is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
RationalRabbit's Avatar
RationalRabbit RationalRabbit is offline Offline
Newbie Poster

Help Iframe inside close - Is there a better way?

  #1  
Nov 13th, 2007
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:
  1. function OpenFrame(ID)
  2. {
  3. newID = ID;
  4. var makeframe=document.createElement("iframe");
  5. makeframe.setAttribute("id", "PopIframe");
  6. makeframe.setAttribute("class", "PopIframe");
  7. makeframe.setAttribute("name", "PopIframe");
  8. makeframe.setAttribute("frameborder", "0");
  9. makeframe.setAttribute("src", "detailbox.php?ID=" + newID); // ID=Database record ID for item search
  10. makeframe.setAttribute("scrolling", "no");
  11. document.body.appendChild(makeframe);
  12. }
  13.  
  14. function ClosePopup()
  15. {
  16. var ifr = parent.document.getElementById("PopIframe");
  17. ifr.parentNode.removeChild(ifr);
  18. }
  19.  
In detailbox.php:
  1. <a class="CloseLink" href="javascript:void(0);" onclick="window.parent.ClosePopup();">X</a>

The product has 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 ID get.

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.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Apr 2007
Location: Birmingham
Posts: 378
Reputation: Fungus1487 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 38
Fungus1487's Avatar
Fungus1487 Fungus1487 is offline Offline
Posting Whiz

Re: Iframe inside close - Is there a better way?

  #2  
Nov 14th, 2007
why not hide/show the iframe instead of creating a new instance each time.

i.e.
on page startup create a hidden iframe
when openframe is called change the visibility and use document.frame.location = '.....' to change the url.

if your using php also depending ont he amout of code the server will have to compile, run and show the results of whatever your doing. You can try using zend or something to precompile the php that may increase performance.

also

makeframe.setAttribute("class", "PopIframe");
is not compatible with all browsers, some use className as i am aware
When Autumn Falls [ http://www.whenautumnfalls.co.uk ] &&
Designdotworks [ http://www.designdotworks.co.uk ] Web / Graphic / Software Design
Reply With Quote  
Join Date: Nov 2007
Posts: 2
Reputation: RationalRabbit is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
RationalRabbit's Avatar
RationalRabbit RationalRabbit is offline Offline
Newbie Poster

Re: Iframe inside close - Is there a better way?

  #3  
Nov 14th, 2007
Fungus -

Thanks much for the tip on "class" vs "classname". I'll check that out.

Originally, I was simply hiding/unhiding the iframe. Besides a simple JavaScript routine to The method I used was the following:
  1. function OpenPopup()
  2. {
  3. z = document.getElementById('PopIframe');
  4. z.style.display = "block";
  5. }
  6.  
  7. function AddID(ID)
  8. {
  9. newID = ID;
  10. x = document.getElementById('PopIframe');
  11. x.src = (x.src + "?id=" + newID); // ID for database lookup
  12. }
  13.  
  14. function ClosePopup()
  15. {
  16. y = document.getElementById('PopIframe');
  17. y.style.display = "none";
  18. }

The problem here was that when I would reopen the iframe, the first thing I would see was the last iframe content. No matter what order I put things in, as far as calling up the selected content and unhiding the iframe, the result was still the same; old content - blip - new content. Destroying then rebuilding the frame, of course, eliminates that, but as I say, is a bit slow. I tried some method (sorry - no notes) that was supposed to clear any cache, but no acceptable result.
Last edited by RationalRabbit : Nov 14th, 2007 at 9:33 pm. Reason: Add open function
Reply With Quote  
Join Date: Apr 2007
Location: Birmingham
Posts: 378
Reputation: Fungus1487 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 38
Fungus1487's Avatar
Fungus1487 Fungus1487 is offline Offline
Posting Whiz

Re: Iframe inside close - Is there a better way?

  #4  
Nov 15th, 2007
you could always create an html page with a prompt something ike 'Loading.. Please wait' and upon hiding your iframe change the location to ths page.

then when opening the iframe they will see a lovely message awaiting them.

in my opinion
document.framename.location = 'url';
is faster than accessing its src attribute node but i am unsure and probly would save u 10th's off a second.
When Autumn Falls [ http://www.whenautumnfalls.co.uk ] &&
Designdotworks [ http://www.designdotworks.co.uk ] Web / Graphic / Software Design
Reply With Quote  
Join Date: Jun 2006
Location: India
Posts: 7,012
Reputation: ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold 
Rep Power: 25
Solved Threads: 368
Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Lazy, Useless & Apathetic

Re: Iframe inside close - Is there a better way?

  #5  
Nov 15th, 2007
> some use className as i am aware
Almost all browsers out there support className. IE doesn't play well with setAttribute so it's wise not to use it.

> document.framename.location = 'url';
IFrames don't have a property named as location. Use the src property instead.
I don't accept change. I don't deserve to live.

Happiness corrupts people.

Failing to value the lives of others cheapens your own.
Reply With Quote  
Join Date: Apr 2007
Location: Birmingham
Posts: 378
Reputation: Fungus1487 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 38
Fungus1487's Avatar
Fungus1487 Fungus1487 is offline Offline
Posting Whiz

Re: Iframe inside close - Is there a better way?

  #6  
Nov 15th, 2007
i stand corrected.
When Autumn Falls [ http://www.whenautumnfalls.co.uk ] &&
Designdotworks [ http://www.designdotworks.co.uk ] Web / Graphic / Software Design
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JavaScript / DHTML / AJAX Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 5:09 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC