In doing the company's CMS when some of the problems of JS, which is in the page is not in the input box in the Back button [backspace key] When the page will jump to the previous page, but the previous page load failed, said the session has expired,
The problem description ends here.
Solution:
The first instinct is to search the internet for answers, but the results are not ideal.
The second on the forum to see if there is no solution to be found a similar to ask you
' How do I know when I press the BACKSPACE key in IE in the input or in the Chinese box? '
Address: http://www.iteye.com/problems/3272
The problem is similar, but it's not a solution, but it's just that I try to find a solution based on his thinking.
Thanks, Fuwang.
Here's My Code:
Window.onload=function () {/**************************** * Author: q821424508@sina.com * * Time: 2012-07-12 * * * * version:1.0 * * ****************************/D Ocument.getelementsbytagname ("Body") [0].onkeydown =function () {if (event.keycode==8) {var elem = Ev
Ent.srcelement;
var name = Elem.nodename;
if (name!= ' INPUT ' && name!= ' TEXTAREA ') {event.returnvalue = false;
return;
var type_e = Elem.type.toUpperCase (); if (name== ' INPUT ' && (type_e!= ' TEXT ' && type_e!= ' TEXTAREA ' && type_e!= ' PASSWORD ' &&
type_e!= ' FILE ') {event.returnvalue = false;
return; } if (name== ' INPUT ' && (elem.readonly==true | | elem.disabled ==true)) {Event.return VAlue = false;
return; }
}
}
}
The problem was solved,
Instructions for use:
1. Copy the code directly to the page, "the page must contain the body tag"
2. Put to any one page referenced js file "directly to the beginning of the file, or finally, do not put into the method, the page must contain the body tag"
The above version is 1.0 and only IE is supported:
The following is the 2.0 version, support ie,firefox,chrome[this three browser tested] and other browsers
Cool (and fix a bug that's a modest one, now 2.1)
Window.onload=function () {/**************************** * Author: q821424508@sina.com * * Time: 2012-08-20 * * * * version:2.1 * * ****************************/D Ocument.getelementsbytagname ("Body") [0].onkeydown =function () {//Get event object var Elem = even T.relatedtarget | | event.srcelement | | Event.target | |
Event.currenttarget; if (event.keycode==8) {///Judge key to BACKSPACE//Get button to press the cursor to point to the element var Elem = Event.srcelement | |
Event.currenttarget; See more highlights of this column: http://www.bianceng.cn/webkf/script///Determine if you want to prevent the keyboard from pressing the event by default to pass Var nam
e = Elem.nodename;
if (name!= ' INPUT ' && name!= ' TEXTAREA ') {return _stopit (event);
var type_e = Elem.type.toUpperCase (); if (name== ' INPUT ' && (type_e!= ' TEXT ' && type_e!= ' TEXTAREA ' && type_e!= ' PASSWORD ') &am
p;& type_e!= ' FILE ') {return _stopit (event);
} if (name== ' INPUT ' && (elem.readonly==true | | elem.disabled ==true)) {
Return _stopit (event); }}} function _stopit (e) {if (e.returnvalue) {e.returnvalue = FA
LSE;
} if (E.preventdefault) {e.preventdefault ();
return false; }
Welcome to Pat Bricks.
Welcome to use in your own project, copy, spread, all can, but please indicate the source.
Version Upgrade:
Current Version 2.1
Fix Firefox can not delete the characters in the input bug
Description
Do not know for Mao, in Firefox under the problem, before the test, and then there is a child shoe said this script in Firefox can not be used, will appear above the phenomenon, I said I debug, but then he said again, it is OK,
But after my test, the script does have a problem.
These problems do occur, but sometimes they are not.
Forget it or change it,
The cause of the problem occurs:
Firefox under var elem = Event.relatedtarget | | Event.srcelement cannot get to the target object.
So change to target attribute to get.
OK Welcome to continue to use
If you have any questions, please ask me to fix them.