/    Sign up×
Community /Pin to ProfileBookmark

document.attachEvent problem

hi,
I’m using document.attachEvent to trap the f5 button when pressed by any user. document.attachEvent works fine with IE7 but mozilla firefox errors out the following
“document.attachEvent is not a function”
does anyone know how to fix this. Please let me know.

thanks,
karthik

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@karthik_jscriptauthorJul 02.2007 — thanks for the help,

I use document.addEventListener for Netscape now, the following piece of code is what I use for trapping and acting on f5. this again works for IE but not for firefox. the event.keyCode returns nothing when used in firefox. any idea?

switch (event.keyCode)

{

case 116 : // F5

// alert("f5");

alert(navigator.appName);

event.keyCode = 0;

event.returnValue = false;

}*/
Copy linkTweet thisAlerts:
@karthik_jscriptauthorJul 02.2007 — thanks for the help,

I use document.addEventListener for Netscape now, the following piece of code is what I use for trapping and acting on f5. this again works for IE but not for firefox. the event.keyCode returns nothing when used in firefox. any idea?

switch (event.keyCode)

{

case 116 : // F5

// alert("f5");

alert(navigator.appName);

event.keyCode = 0;

event.returnValue = false;

}*/
Copy linkTweet thisAlerts:
@karthik_jscriptauthorJul 02.2007 — i used the following to get the key pressed in firefox

var theEvent=window.event/*this is for IE*/ || arguments[0]/* this is for Netscape and firefox*/;

var code = theEvent.keyCode;

?

thanks for the help.
×

Success!

Help @karthik_jscript spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.1,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...