Forum Moderators: open

Message Too Old, No Replies

Code to disable backspace

         

alexawy

5:13 pm on Jan 23, 2011 (gmt 0)

10+ Year Member



Hi.
I've a website 100% build on Ajax.

When the visitor click on Backspace, he is returned to the previous website he was in, and so goes away from the website.

Is there anyway to disable the backspace utility.

thanks.

Fotiman

6:25 pm on Jan 23, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



This is standard browser functionality. It's not a good idea to change that behavior, as some people who browse primarily with keyboard will only be frustrated by it.

piskie

9:57 pm on Jan 23, 2011 (gmt 0)

10+ Year Member



You may also trigger some security software as an intrusive behaviour.

alexawy

9:01 am on Jan 24, 2011 (gmt 0)

10+ Year Member



This is standard browser functionality

I want to disable this as this is the standard browser functionality. When the user click backspace he is expecting to go to the previous page.

Ajax does NOT allow this.

so I want to catch the refeering page by any code, when the user click BACKSPACE he is back (by ajax too) to the page he came from.


I saw many posts in this forum but non worked with me.

alexawy

9:03 am on Jan 24, 2011 (gmt 0)

10+ Year Member



the code I found, but didn't work.

<script>
function checkShortcut()
{
if(event.keyCode==8 ¦¦ event.keyCode==13)
{
return false;
}
}
</script>
<body onkeydown="return checkShortcut()">

alexawy

9:13 am on Jan 24, 2011 (gmt 0)

10+ Year Member



this simple script return the keyCode of the button, It is working fine for all the KEYS except the functions keys (Ctrl, Shift, Backspace).

any help

<body onkeypress='alert(event.keyCode)'></body>

piskie

9:28 am on Jan 24, 2011 (gmt 0)

10+ Year Member



Whoops wrong topic

[edited by: piskie at 9:29 am (utc) on Jan 24, 2011]

alexawy

9:28 am on Jan 24, 2011 (gmt 0)

10+ Year Member



Progress:
this code disable the Backspace on IE
<script>
if (typeof window.event != 'undefined')
document.onkeydown = function()
{
if (event.srcElement.tagName.toUpperCase() != 'INPUT')
return (event.keyCode != 8);
}
else
document.onkeypress = function(e)
{
if (e.target.nodeName.toUpperCase() != 'INPUT')
return (e.keyCode != 8);
}
</script>

alexawy

9:33 am on Jan 24, 2011 (gmt 0)

10+ Year Member



Final Reply: IT WORKED

<script>
function checkShortcut()
{
if(event.keyCode==8 || event.keyCode==13)
{
alert('Hi'); return false;
}
}
</script>
<body onkeydown="return checkShortcut()">


alert will be changed to ajaxpage("my refering page", "mytarget")