[ajax] key disabling using javascript

This is a scriptlet I found in the web. I guess these would be pretty useful in the Ajax context.


/*****
// Suppress Keys (Back Space) - Start
window.history.forward(1);
function _suppressKeyPress()
{

//alert(event.keyCode);
/*Key Codes
112 -> F11
8 ->
Backspace
116 -> F5
115 -> F4
93 -> Windows Properties Key
17 -> CTRL
*/
//======================================================
// Disable CTRL
Key
//======================================================
keys = new
Array();
keys["f17"] = 'Ctrl';
keys["f8"] = 'Backspace';

saveCode=""
if(window.event && window.event.keyCode == 17)
{
saveCode=window.event.keyCode;
window.event.keyCode = 505;
}
if(window.event && window.event.keyCode == 505)
{
alert('Ctrl has been disabled');
return false;
}
//======================================================
// Disable
Backspace Key
//======================================================
if(window.event && window.event.keyCode == 8
&& !window.document.activeElement.isTextEdit)
{
saveCode=window.event.keyCode;
window.event.keyCode = 506;
}
if(window.event && window.event.keyCode == 506)
{
//alert('Backspace has been disabled');
return false;
}
//======================================================
// Disable F5
Key
//======================================================
if(window.event && window.event.keyCode == 116 )
{
saveCode=window.event.keyCode;
window.event.keyCode = 507;
}
if(window.event && window.event.keyCode == 507)
{
alert('F5
has been disabled');
return false;
}
//======================================================
if(event.keyCode == 122 event.keyCode == 115 event.keyCode == 93)
{
event.keyCode = 0;
event.returnValue = false;
}
}
//------------------------------------------------------------------
//
Capture Key Press event & call the function to suppress the event
//------------------------------------------------------------------

window.document.onkeydown = _suppressKeyPress;
//-----------------------------------------------------------
//
Suppress Right click - Start
//-----------------------------------------------------------
var
message="VFS";
function click (e)
{
if (document.all)
{
if
(event.button ==2event.button==3)
{ alert("Access Denied");
return
false;
} }
if (document.layers)
{
if (e.which == 3)
{
alert(message); return false;
} } }
if (document.layers)
{
document.captureEvents(Event.mousedown);
}
// Capture Right click
event & call the function to suppress the event
document.onmousedown=click;

//-----------------------------------------------------------
*//////
// Suppress Keys (Back Space) - Start
window.history.forward(1);
function _suppressKeyPress()
{

//alert(event.keyCode);
/*Key Codes
112 -> F11
8 -> Backspace
116 -> F5
115 -> F4
93 -> Windows Properties Key
17 -> CTRL
*/
//======================================================
// Disable CTRL Key
//======================================================
keys = new Array();
keys["f17"] = 'Ctrl';
keys["f8"] = 'Backspace';

saveCode=""
if(window.event && window.event.keyCode == 17)
{
saveCode=window.event.keyCode;
window.event.keyCode = 505;
}
if(window.event && window.event.keyCode == 505)
{
alert('Ctrl has been disabled');
return false;
}
//======================================================
// Disable Backspace Key
//======================================================
if(window.event && window.event.keyCode == 8 && !window.document.activeElement.isTextEdit)
{
saveCode=window.event.keyCode;
window.event.keyCode = 506;
}
if(window.event && window.event.keyCode == 506)
{
//alert('Backspace has been disabled');
return false;
}
//======================================================
// Disable F5 Key
//======================================================
if(window.event && window.event.keyCode == 116 )
{
saveCode=window.event.keyCode;
window.event.keyCode = 507;
}
if(window.event && window.event.keyCode == 507)
{
alert('F5 has been disabled');
return false;
}
//======================================================
if(event.keyCode == 122 event.keyCode == 115 event.keyCode == 93)
{
event.keyCode = 0;
event.returnValue = false;
}
}
//------------------------------------------------------------------
// Capture Key Press event & call the function to suppress the event
//------------------------------------------------------------------

window.document.onkeydown = _suppressKeyPress;
//-----------------------------------------------------------
// Suppress Right click - Start
//-----------------------------------------------------------
var message="VFS";
function click (e)
{
if (document.all)
{
if (event.button ==2event.button==3)
{ alert("Access Denied");
return false;
} }
if (document.layers)
{
if (e.which == 3)
{ alert(message); return false;
} } }
if (document.layers)
{
document.captureEvents(Event.mousedown);
}
// Capture Right click event & call the function to suppress the event
document.onmousedown=click;

//-----------------------------------------------------------

Advertisements
  1. #1 by sana on March 15, 2007 - 12:55 pm

    gduigdgg

  2. #2 by sana on March 15, 2007 - 12:55 pm

    HDU8YHEWYHHWJHDUGUDSSJDHUHGSDUHU;SHUSDHUA

  3. #3 by Fortes on August 20, 2007 - 12:58 pm

    thank you…. great script

    —-
    Fortes
    escalando.net

  4. #4 by Andy on December 19, 2007 - 5:49 pm

    Oh, and did not know about it. Thanks for the information …

  5. #5 by Senthur on April 14, 2008 - 6:22 am

    Hi folk,
    Thats really nice… Thaks a lot for the code.

    Thanks,
    Senthur.

  6. #6 by Amy on September 21, 2008 - 12:31 pm

    Hi, I have a little problem and came across your website as I was trying to look for answers. I’m not a programmer, so I don’t know how to read codes, but find this code of yours I think is close to what I was looking for. Basically what I need is to disable hotkeys of firefox.

    Alt F for File
    Alt E for Edit
    Alt V for View
    Alt S for History
    Alt B for Bookmarks
    Alt Y for Yahoo
    Alt T for Tools
    Alt H for Help
    Ctrl W

    I don’t mean to impose, but I have searched all over and have asked people and still couldn’t find the solution to this problem. I was wondering if you might be able to help me in this. Your feedback is very much appreciated and I look forward to hearing from you

    Many thanks
    Amy from the Philippines

  7. #7 by tally on September 26, 2008 - 5:39 am

    he’lo

    check out this script for disable keys
    works for safari, mozilla & ofcourse in IE ……

    just add key_code in if() u want to disable

    function disableKeys(e)
    {
    // get key code
    var key_code = (window.event) ? event.keyCode : e.which;

    var ctrl_key = (window.event) ? event.ctrlKey : e.ctrlKey;

    // case : if key is enter or escape or F5 or ctrl+n or ctrl+r then avoid it
    if ( key_code==13 || key_code==27 || key_code==116 || ctrl_key && (key_code == 78 || key_code == 82) )
    {

    // case :if it is IE event
    if (window.event)
    {
    window.event.returnValue = null;
    event.keyCode=0;
    }

    // case: if it is firefox event
    else
    e.preventDefault();

    }
    }

  8. #8 by MFZ on May 6, 2009 - 10:52 am

    I am using a pdf control on my page and I want to disable the toolbar of that control, does any one has the solution?
    If yes so please post as soon as possible.

    And I just want to disable all the browser functions like Refresh button, back and forward buttons etc.

    Looking for prompt response.

    Thanks and Regards.

  9. #9 by Z@9YT@ on October 9, 2009 - 1:43 am

    Those buttons belong to user. U can’t disable it.
    If in IE u can use:
    window.history.forward();
    is it support to other browser? i.e. NN, Safari, Opera, Chrome.

    Sori about my English. 🙂

  10. #10 by subodh kant on December 29, 2010 - 10:28 am

    how can disabled ctrl keys and copy in javascrip .when we r using Getnextedu pannel

  11. #11 by spelen on February 17, 2011 - 12:56 pm

    Any solution?

  12. #12 by Harshal Vasani on August 10, 2011 - 6:04 am

    Please use the following code to disable Ctrl key and mouse clicks,

    var flag;

    function disablemouse(key)
    {
    if(key == 1 && event.button == 0)
    {
    alert(“Access Denied”);
    return false;
    }
    }

    function disableKeys(e)
    {
    var ctrl_key = (window.event) ? event.ctrlKey : e.ctrlKey;

    if(ctrl_key)
    {
    flag = 1;
    }
    else
    {
    flag = 0;
    }

    disablemouse(flag);
    }

  13. #13 by Cheap Blog Comments on August 28, 2011 - 5:48 pm

    Real nice design and good articles , hardly anything else we want : D.

  14. #14 by Karan Vyas on March 10, 2012 - 11:45 am

    Can this code be used to disable the Ctrl + (zoom in) and Ctrl – (zoom out) effect keys?

  15. #15 by health insurance on April 11, 2013 - 10:11 pm

    Hello, Neat post. There is a problem with your site
    in internet explorer, may test this? IE nonetheless
    is the marketplace chief and a large portion of
    people will pass over your excellent writing because of this
    problem.

  16. #16 by coupon website on May 5, 2015 - 7:58 am

    Hi, I ran across your web blog through Bing when evaluating a similar issue, your web blog got here right up, it seems great.. coupon website I’ve got included in favourites types|put into bookmarking.

  1. Dota 2
  2. Office 2010 Serial Key
  3. DFDS Seaways Voucher Codes|Discounts|Discount Codes
  4. dota 2 cast

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: