http - JavaScript key undefined in IE over SSL -


i'm working on web app works fine inside lan using http when test remotely on ssl fails ie (7 & 8). firefox, camino , safari work perfectly.

i've tracked down issue key being undefined. relevant bit of code is:

function showresult(e,str,num) {     var key = (window.event) ? e.which : e.keycode;      if(((key > 32 && key < 58) || (key > 64 && key < 91) || (key > 95 && key < 123)) && (str.length >= num)) { 

any clues why key undefined ie on ssl works fine on http? better yet, can tell me how overcome problem? fwiw, don't need support ie prior version 7.

update:

there answer suggested replacing

var key = (window.event) ? e.which : e.keycode; 

with

var key; e = e || window.event; key = e.keycode || e.which; 

that works. problem can't accept answer because has been deleted.

ok, i'll re-add answer, though wasn't mine, , add info along way can feel ok accepting if wasn't answer beginning.

so, suggested code this:

var key; e = e || window.event; key = e.keycode || e.which; 

what || do? 1 it's logical or operator, return true if 1 of sides evaluate boolean true.

it has use in js. if give 2 arguments , first 1 undefined, return second argument. means, in code above, if e undefined, instead window.event ie's traditional event object.

same thing goes e.keycode || e.which whichever 1 exists used. in end, you're end valid key code on various browsers. in wonderland.

but wait, doesn't original code similar?

var key = (window.event) ? e.which : e.keycode; 

uh-huh. what's that? javascript case-sensisitive, window.event not same window.event in code above. window.event ie's traditional event object use information event occurred, while window.event (which can see initial capital letter) constructor, or more in case an interface.

point is, in code used detect mozilla. if exists, choose e.which (one of places mozilla stores key code) otherwise go e.keycode ie store key code.

however, based on flawed assumption ie doesn't have window.event constructor defined. have defined of ie8, @ least. means e.which chosen on e.keycode, on newer versions of ie. e.which has never , never supported in ie. that's why key ends being undefined.

but, uhm, why differ between encrypted , unencrypted connections? that's question. while cannot know sure without access development environment, assume has ie's compatibility modes.

ie has historically (over last 10 years) been quirky , non-standard browser around. has lead people a) programming ignorantly according ie's standards b) creating workarounds ie's behaviors. if ms made ie standards-compliant, break many pages rely on ie's quirky behavior in 1 way or other. microsoft has ackowledged making ie8+ emulate older versions of ie pages won't break, unless told otherwise.

i can assume that, whatever reason, in test environment page ends running in "ie7" mode might not have window.event constructor/interface defined. make old code use e.keycode ey ok. perhaps in production environment, or maybe because of encrypted connection (only ghawd knows ms doing) end newer ie mode window.event defined , e.which chosen. makes ie cheeky monkey.

bottom line: use new code.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -