Jump to content
xisto Community
Sign in to follow this  
hippiman

Javascript Events Not Working For Ie

Recommended Posts

I just made this little html file and I used javascript to show which arrows you're pressing. It just says the key code, but only for the arrows, so it will say "37, 38, 39, 40" if you're pushing all the arrows. When you let go of the arrows, it won't show that value.
It works perfectly in Firefox, but I can't get it to run in Internet Explorer. The little notification bar down in the bottom left of the window says there's an error, and it just sits there.
All I used was a function for onKeyDown and onKeyUp on the body, and every 10 milliseconds it shows what keys you have pushed.

Here is a link to what I have so far: Javascript Thing

If you have Firefox, all you have to do is click on the page anywhere, and start pressing the arrows, and it should work. But in IE, all it does is display all the numbers, no matter what keys you're pushing. You can look at the page source to see what's going on, but the only functions you should have to look at are dispMultiKeys(), setKeyDown(e), and setKeyUp(e). All the other functions are just because I was messing around trying to figure stuff out.

I did the "saved from internet" thing at the top so IE wouldn't say the thing about ActiveX controls.

The "e = e || window.event; code = e.keyCode || e.which;" is supposed to make the key events work for most browsers.
dispMultiKeys() happens every 10 milliseconds, and it just displays what keys you're pressing. I just used setInterval.
I declared 2 arrays at the beginning, and the keysPressed array is just to say what keys are down, and the other one is just supposed to help declare it, because it wouldn't work using keysPressed[37, 38, 39, 40] and looping through that setting it all to false.

I don't really use IE that much, but I just want all my stuff to work for everyone.
If anyone can figure out what I'm doing wrong so it doesn't work with IE, I'd appreciate it. Thanks in advance!

Share this post


Link to post
Share on other sites

Have you tried removing the two forward slashes in:

onload="KeyTester=setInterval('dispMultiKeys()', 100);//Frames=setInterval('dispDimensions()', 1000);"

?Also, check to see if your Internet Explorer supports the canvas element.

Share this post


Link to post
Share on other sites

The forward slashes are just to make the line a comment. It shouldn't have any problem with that in any browser that's javascript compatible.And I've also found out that I can't get anything with loops or events in javascript to work with IE. It says something about ActiveX controls, then it just goes through the loop once. I'm just using a 'for' loop, which works perfectly in FF.I think it might be having problems with the "document" element. There was one page that said something about using "document.all", but that didn't help at all, either. It might be something to do with my settings in IE, too.I guess I'll just have it say that it only works in FF or something, whenever someone with IE tries to view the page. Oh, well.

Share this post


Link to post
Share on other sites

you should try making your html complete. Add the <html> tags and the <head>. Add a doctype too so that the browser knows what the hell it's supposed to do. If you do all that and make your page standards compliant it might work in more browsers.

Share this post


Link to post
Share on other sites

you should try making your html complete. Add the <html> tags and the <head>. Add a doctype too so that the browser knows what the hell it's supposed to do. If you do all that and make your page standards compliant it might work in more browsers.

Most recent popular browsers that people use can work without the heml tag, head tag or doc id. Perhaps if you are testing it on an older browser that might pose some problems but this wouldn't fix anything. I am quite curious of the comment in your onload event. I'm not quite sure all browsers like comments in there. Try removing that comment, i mean since you have it commented out it shouldn't be necessary right?

Share this post


Link to post
Share on other sites

Not that this really matters, but my account should be back up in a couple of hours, according to the thing.I probably should have just copied my HTML file and posted it as part of this topic, though, because I'm kind of slow at posting, and I've had this happen before.Thanks for the comments, though. I need to check some of that out when my account gets back up.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.