views:

23

answers:

1

As you all know, when we hit the refresh button, the entire page starts to reload. But I dont that, I only want to refresh some portions, which need to be refresh in case of a need.

I know, I can use ajax to reload a piece of content. But I want to attach this ajax function while the user clicks the refresh button or presses F5 or presses Ctrl+F5.

+7  A: 

Don't do this, don't attempt to do this, you're breaking the behavior that the user has come to expect from their browser, this should not be overridden in any way. Nothing outside of the frame containing your page should be affected by your code, that's the user's browser, not yours.

Refresh has a purpose, they want to re-load the content, what if your script breaks, what if it's a JavaScript error? They may need a browser refresh to fix the issue...this is one of a thousand valid reasons, none of which should behave unexpectedly.

Disregarding the why you shouldn't above, you can't do this, not in every browser...for exactly the reasons I provided above plus many more.

Nick Craver
Well, you are propably right, but some contents which have properly loaded, dont need to be reloaded, like menubar, banner, why do we need to reload that
Starx
@Starx - You can provide a refresh icon of some sort *in* your page, but don't try to override the basic functionality of the browser.
Nick Craver
@Starx: This is why the browser will cache them. It's not your problem to deal with.
Duracell
Yes, I agree on this, But I just want to know if there is a way to accomplish this
Starx
@Starx: There isn't, advertisers would abuse the hell out of it if there were :) When you think of why a feature doesn't exist, also consider "how could it be exploited/abused?"...therein usually lies the reason.
Nick Craver