-
FEATURED COMPONENTS
First time here? Check out the FAQ!
hello all,
I need to detect when the user presses the button to refresh the screen (F5) or disable this feature, anyone can help me?
Thanks
You can't restrict the user to stop refreshing the page. The browser is user's application and he has all the rights to do what ever he wants to do with his application he can close it open it navigate where ever he wants. If you are developing web application you shouldn't put these restrictions in your web pages. If you need such an ability you should consider developing desktop applications either in Win32 or .NET etc..
The other alternative is Adobe AIR or Site specific browsers (SSB) using that you can deploy your web applications on to users desktops. These give you an ability to control user actions.
you can do this with JavaScript.
to hide toolbar, menu ... etc., open your web application with this JS function that you can set according to your needs :
window.open("yourZKWebPage","windowName","width=200,height=100,toolbar=no,location=no,directories=no ,status=yes,menubar=no,scrollbars=no,resizable=yes");
And here, is an old code to intercept keyboard input, you can also customize it according to your needs :
function keydown() { if ((window.event.ctrlKey) || (window.event.shiftKey) || (window.event.keyCode==18) || ((window.event.keyCode>=112) && (window.event.keyCode<=123))) { if (window.confirm("Shortcuts are not allowed ! \nDo you want to exit this great site ?" )) top.close(); else { setTimeout("form.focus();",30); window.event.returnValue = false; } } } document.onkeydown= keydown //All Keys are checked
I tried following code in zk5, it works.
You have to use jquery to cross browser.
<zk>
<window title="forum 11347">
Hello, World!
<label id="aa" value="dd"/>
<button label="change" onClick='aa.value="cc"'/>
</window>
<script><![CDATA[
(function($) {
$.fn.extend({
disableF5Key: function() {
$(window.document).keydown(disableF5InnerFunc);
}
});
function disableF5InnerFunc(event) {
var e;
if ($.browser.msie) { e = window.event; } else { e = event; }
if (e.keyCode == 116) { e.keyCode = 0; return false; }
if (e.altKey && (e.keyCode == 37 || e.keyCode == 39)) { return false; }
};
})(jQuery);
$.fn.disableF5Key();
]]>
</script>
</zk>
@Thiru,
for ZK3.5, you have to include jquery lib manually.
About browser refresh icon, you may google, see if there is sample javascript code for it.
After all, the above sample just use <script> to execute javascript in browser.
The rest is how to implement it in javascript.
Thanks for the great post it really helped me. Works in all browsers IE, firefox, opera and tested it in ZK 6!
Asked: 2010-02-15 10:40:15 +0800
Seen: 1,601 times
Last updated: Oct 02 '12