• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

Frames loading twice on refresh

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all!

I have a problem. I am using frames and when the page is being refreshed, the frame is being loaded twice. This is the scheme I am using.


The javascript sets the frame because the URL is dependent on some URL parameters. But anyway...

Why is the frame being loaded twice when I hit refresh? It is loading it twice in IE 7 and Firefox 3, but not in Safari 3 (for win xp).

And of course for the real question, how do I get it to load only once!?
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What do you mean exactly frames are being loaded twice?

Eric
 
Ranch Hand
Posts: 838
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you post exactly what you're dealing with? If you're loading the same page (which I'm guessing you aren't) why not just put that in the src of the iframe tag straight up? Could you post the whole page (re-word specifics of course)? Sometimes if you post what you think is the same as what you've got you may leave out something important.
 
Dave Stolie
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is wrong with the sample provided? I replaced the url with http://www.google.com and it loads the URL twice in the frame for me using FireFox 3 and IE 7 when I hit refresh. (But not on Safari for Win XP)

(What is a quick and easy photo hosting/sharing site? I can post a screen shot detailing the two requests.)

The only thing I can think of is that the browser is trying to be 'smart' reloading the frame itself. It is reloading once before the javascript. Then once it is reloaded, it is then running the onLoad javascript function loading the frame again. If this is actually the case, how do I prevent it from being loaded a second time?

I tried the following with no luck:




why not just put that in the src of the iframe tag straight up?


The specific URL is dependent on a URL parameter. The page the iframe is on is a just a simple htm page that is not under my control. It is not a JSP page or anything that dynamically creates it's content. This is why I can't hard code the iframe's src.
 
Sheriff
Posts: 67735
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dave Stolie wrote:(What is a quick and easy photo hosting/sharing site? I can post a screen shot detailing the two requests.)


You can attach images to your post.

This is why I can't hard code the iframe's src.


Not grokking that. The type of content (JSP or HTML) has nothing to do with the URL that you assign to the frame.

However, if the URL needs to be dynamic for some other reason, why aren't you determining it on the server and dispensing with all the client-side machinations?
 
Dave Stolie
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Eric Pascarello wrote:What do you mean exactly frames are being loaded twice?

Eric



The iframe is making two requests to populate its frame contents. It is actually making two calls to google, loading it twice.
 
Dave Stolie
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The highlighted row is the start of the second request. All this is from after the page first loaded, starting upon hitting refresh.
googleLoadTwice.JPG
[Thumbnail for googleLoadTwice.JPG]
The two requests to google
 
Rob Hunter
Ranch Hand
Posts: 838
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"What is wrong with the sample provided?" The problem was that the example was using javascript when you didn't need javascript. If you are just going to use javascript to set the URL to the same thing then why not just set src straight up? You mentioned some dynamic setting of of the URL for the frame but your examples don't show anything of that nature. You have the url hardcoded in the javascript. I'll assume what you are trying to accomplish and this example are 2 different animals and that this is just test code.
Here are 2 things to try:
A) iquery - look at calling the function once the page is finished loading using this library
B) instead of using onLoad just have a script at the bottom that calls the script at the top.
Just a few things to try. You have the src set to "x" in your example, is this what you've actually tried? When the alert gets hit has the iframe already loaded www.google.com? What is in the iframe when the laert gets hit if this was not the case?
 
Rob Hunter
Ranch Hand
Posts: 838
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmmm. I was going by the code so I decided to copy that segment you had posted and I get the same thing. I also tried putting in the line document.getElementById("theFrame").src = document.getElementById("theFrame").src; before the alert and the iframe didn't change so the bit I posted before... throw that out. My guess is it's caching the iframe or the iframe just doesn't reset when refreshing the main page. Instead of trying x as the initial source I tried a legitimate site (www.tsn.ca) and still couldn't set back the original page with the line posted above. Bear, with embedded objects such as this do they get treated the same as the parent page when refreshing? What's the best alternative to using the iframe? Object? .....
 
Dave Stolie
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:

This is why I can't hard code the iframe's src.


Not grokking that. The type of content (JSP or HTML) has nothing to do with the URL that you assign to the frame.

However, if the URL needs to be dynamic for some other reason, why aren't you determining it on the server and dispensing with all the client-side machinations?



I am stuck with this. The project I am working on is being done in two parts. One team is doing the designing of the page and hosting most of the pages on their server. Their pages are not JSP pages or anything that is generated by some logic, but plane simple HTML files. My part of the project is to provide the site with functionality to log a user in, allow them to update some info, and then send them over to a third party vendor which handles some ordering. All of the business logic is done by us. Their files are being hosted on their server under the site's URL and they are using frames to consume the user management functionality hosted by us while remaining under the same URL.

The reason the src of the iframe on this page is set through javascript is because I have to send a user to their (the other teams) static HTML page and pass along a session ID. Then the javascript sets the src of the iframe to a URL which consists partially of that session ID so they can then make the call back to us. The whole process is working fine with the exception of when a user hits refresh on a page. It is then making the call to us twice each time they are doing so.
 
Dave Stolie
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Hunter wrote:"What is wrong with the sample provided?" The problem was that the example was using javascript when you didn't need javascript. If you are just going to use javascript to set the URL to the same thing then why not just set src straight up? You mentioned some dynamic setting of of the URL for the frame but your examples don't show anything of that nature. You have the url hardcoded in the javascript. I'll assume what you are trying to accomplish and this example are 2 different animals and that this is just test code.
Here are 2 things to try:
A) iquery - look at calling the function once the page is finished loading using this library
B) instead of using onLoad just have a script at the bottom that calls the script at the top.
Just a few things to try. You have the src set to "x" in your example, is this what you've actually tried? When the alert gets hit has the iframe already loaded www.google.com? What is in the iframe when the laert gets hit if this was not the case?



My question was concerning the reloading twice of an iframe upon hitting refresh. I didn't want to complicate the code provided that was to demonstrate the problem at hand. I stated at the beginning why it is set by javascript and not simply hard coded and wanted to keep the sample focused to the problem at hand (Frame loading twice on refresh). I guess trying to cut things down to simply demonstrating the problem only exacerbated the attention away from the problem... I do appreciate your concern and looking into the matter. I can add the other javascript function that pulls a URL param. and appends it to the end of the URL to make it more like the actual case if you would like to see it.

I just tried setting the src to x in an attempt to try to see if the frame had already been set prior to setting it again by the javascript, causing the second load. I figured that since google was already loaded by the refresh in the frame prior to the onLoad call, I could get it's src value and not set it if google was already loaded. But, this did not work as even though google had been reloaded, I was still getting the value of /x as the src, thus still reloading google twice. I attempted this because I believe it is the browser trying to be like Microsoft in doing stuff it thinks you want it to do, even though it is more often then not the case.
 
Rob Hunter
Ranch Hand
Posts: 838
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dave, not sure if you missed it or not but I posted again after the post you quoted. Since the code looked rather simple I thought that you may have been having problems with the scenario you were talking about but trying to take out all the sensitive code to simplify for the readers. My apologies. I don't think the iframe is loading twice but rather just unaffected by the refresh. If you try and set the url to something else before the www.google.com and break you'll likely find it doesn't take. I think once you've set the iframe it's there, in this case anyways. I haven't tried it but I'd be curious to see what would happen if you called a similar script on the onclick of a button after the page has fully loaded. Would you be able to change the src then after a refresh? If you find out anything could you post your findings?
 
Dave Stolie
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Hunter wrote:Dave, not sure if you missed it or not but I posted again after the post you quoted. Since the code looked rather simple I thought that you may have been having problems with the scenario you were talking about but trying to take out all the sensitive code to simplify for the readers. My apologies. I don't think the iframe is loading twice but rather just unaffected by the refresh. If you try and set the url to something else before the www.google.com and break you'll likely find it doesn't take. I think once you've set the iframe it's there, in this case anyways. I haven't tried it but I'd be curious to see what would happen if you called a similar script on the onclick of a button after the page has fully loaded. Would you be able to change the src then after a refresh? If you find out anything could you post your findings?



Yea, I didn't catch your other reply before I posted mine, no need to worry about it. I am just focused on a solution to the double request

The refresh, in fact, is affecting the iframe. If I load the page and then hit refresh, I get a total of three requests for the URL I am setting the iframe to. The initial request is set by the first onLoad javascript call. Then I hit refresh, a request is sent out for the iframe, and then the onLoad is called triggering the third request.

It is the request that happens between hitting refresh and the onLoad function that I do not understand. There is no instruction in the page to tell it to load prior to the onLoad call. I am assuming the browser is doing this and I have no control over this. To get around it, I am wondering if it is possible to tell if the iframe has already been loaded before setting its source. Trying to get its src value just returns what is in the hard coded HTML code even though the browser already made a request to the URL it was set to prior to the page refresh, so I am at a loss on what to do.
 
Rob Hunter
Ranch Hand
Posts: 838
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I get a chance this weekend I'll try a few things myself and see what I can come up with. Have you tried exploring the world of jQuery yet? After seeing people post in here about it I figured I'd do some reading up. Seems interesting but all I've done is observe from the distance. Might be something interesting there for you, setting up a function call on the document ready status or something and bypass the ole onLoad route. Maybe you could try an alternative approach to using the iframe?
 
Dave Stolie
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Rob, thanks for the attention you have given to my issue. Don't be spending much of your time on this. I am pretty confident it is browser behavior in how it handles the iframe on refresh. I opened the code through FireFox, then I changed the URL in the file, saved, then refreshed the page. It proceeded to reload the original URL (prior to the refresh), then triggered the onLoad function loading the iframe with the new URL.

I'm not at all familiar with JQuery. Though, my first thought is that either the issue will still happen with that JavaScript library, or there is a simple alternate route used by JQuery that someone else might know of that I could do here. I could be wrong, but I don't think it would be prudent to load a large library just to do such a simple task. But, I guess if it was the only way...

Like I said, you don't need to spend any more of your time on this unless its for your own edification. Your help has been appreciated, thanks.
 
What are you doing in my house? Get 'em tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic