Search code examples
javascripthtmlrefreshframeset

How to prevent double-refresh on frameset


I have a situation where pressing F5 or CTRL+R causes a frameset to load a frame twice. It happens on localhost, but as I've just put together an example for this question and uploaded it, I notice it varies by browser.

Visiting the link for the first time or clicking the browser address bar and hitting enter performs a 'normal refresh', as desired.

The test case I put together below has 2 frames, one left empty. When frame1.html loads, the frameset then sets frame2's src, which then loads frame2.html. Both should alert only once, but you'll see that is not the case for 'frame2.html'.

Behaviour-by-browser:

  • Chrome16 & Safari5.1 works as expected both localhost/live
  • FF9 double-up on localhost, works as expected live
  • IE9 double-up on both localhost/live
  • haven't tested other / older browsers yet, but I anticipate some agony

I tried clearing the src attribute on the frameset's unload event in the hope it might at least load nothing before doing the double-up and then loading frame2.html, but even if that had worked (which it didn't) it's nasty.

My questions:

  1. Why is the double refresh happening, when it does happen?
  2. Is there a way to prevent the double-up?

Here's the link: http://codefinger.co.nz/public/frameset_test/frameset.html and also the rar'd files: http://codefinger.co.nz/public/frameset_test/frameset_test.rar


Solution

  • Ok, lack of an explanation drove me mad, but I did find a way to stop this default, inconsistent behaviour.

    I listen to the frameset's window.unload event (YUI3.5), and remove the double-up frame node altogether. The double-up goes away, everything appears normal.

    Tested successfully in (both localhost and live server):

    • Chrome 16.0.912
    • Firefox 3.6, 9.0.1
    • IE 6,7,8 & 9
    • Safari 5.1

    Does not work in:

    • Opera 11.61 (I can't access and manipulate the frameset element)

    I'll still +1 for any explanations as to why the frameset load double-up occurs in the first place.