0

I found the way to refresh my article div with the following code when pressing F5. Only article part of div is replaced with a new content.

enter image description here

However, pressing browser's refresh button shows article div as a new page. It's not embedded in the main page. This is not what I want. I want only the div refreshed like when pressing F5.

Is there any jquery event handler for the browser refresh button only?

coder
  • 8,346
  • 16
  • 39
  • 53
drek
  • 41
  • 2
  • 5

2 Answers2

0

Try like following

<div id="div">content 1</div>

$(function(){
    $(document).keydown(function(e){
        e.preventDefault();
        $('#div').load(" #div", function(){
            $(this).children().unwrap();
        });
        return (e.which || e.keyCode) == 116;
    });
});
Anfath Hifans
  • 1,588
  • 1
  • 11
  • 20
  • Hi Anfather thanks, but it still works for F5 button only. When I press refresh button on browser, ariticle div opens as a new page like before. – drek Apr 26 '18 at 06:56
0

There is no way to block refresh button from javascript/jquery, there is a way to block by changing setting in firefox browser, but it will only work on your system, hence not recommended. The best way is to use AJAX, that is the standard way of working when you don't want the page to reload.

Aparajit P Utpat
  • 375
  • 3
  • 14
  • Yes, there seems to be no way to intecept refresh button in code. I should find another way by using AJAX as you recommend, thank you! – drek Apr 26 '18 at 08:57