Preventing F5 inside iFrame with jQuery

Our application has a requirement that users are not allowed to refresh the web page using F5.

I implemented the solution here , however I just discovered that this does not work inside the iframe on the page.

An IFrame is generated using the telerik TV control unit.

I tried the following on my page containing a radio editor.

$(function () {
    $('#<%=RadEditor1.ClientID %>_contentIframe html').bind('keydown', function () {
        if (window.event && window.event.keyCode == 116) {
            window.event.cancelBubble = true;
            window.event.returnValue = false;
            window.event.keyCode = 0;
            window.status = "F5 is disabled on all popups";
            return false;
        }
    });
});

However, it does not work.

Is there anything special in the iframe that I am missing?

+3
source share
3 answers

This method works sequentially.

$(function () {
    function addF5Handler(){
        el = $('body', $('#myframe').contents());
        if(el.length != 1) {
            setTimeout(addF5Handler, 100);
            return;
        }
        $($('#myframe').get(0).contentWindow.document).keydown(function () {
            var myWindow = $('#myframe').get(0).contentWindow;
            if (myWindow.event && myWindow.event.keyCode == 116) {
                myWindow.event.cancelBubble = true;
                myWindow.event.returnValue = false;
                myWindow.event.keyCode = 0;
                myWindow.status = "F5 is disabled on all popups";
                return false;
            }
        });
    }
    addF5Handler();
});
+2
source

, , , . , , , ?

, -?

Gmail , /. , , F5 , - .

+5

I think the only option you have is:

$(window).on('beforeunload', function () {
  return 'Leave?';
});

Put this on your iFrame page.

+1
source

All Articles