开发者

How to alter the Browser's Refresh Event and trigger a custom function?

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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜