Web Design Forum  
 
Go Back   Web Design Forum > Web Software > Scripts

Reply
 
LinkBack Thread Tools Display Modes
Old 10-12-2011, 01:11 AM   #1
Silver Member
 
benjamin.morgan's Avatar
 
Join Date: Aug 2011
Posts: 187
Default Javascript if (typeof(window.event) != "undefined") { problem

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Simple Event Example</title>
<script type="text/javascript">
function addEventHandler(oNode, sEvt, fFunc, bCaptures){
if (typeof(window.event) != "undefined") {
oNode.attachEvent("on" + sEvt, fFunc);
}else{
oNode.addEventListener(sEvt, fFunc, bCaptures);
}
}

function onLinkClicked(e) {
alert("You clicked the link");
}

function setUpClickHandler() {
addEventHandler(document.getElementById('clickLink '), "click", onLinkClicked, false);
}
addEventHandler(window,"load", setUpClickHandler, false);
</script>
</head>
<body>
<a href="#" title="click me" id="clickLink">Click Me!</a>
</body>
</html>
I got this out of a tutorial.
This works fine in FIREFOX. In CHROME and INTERNET EXPLORER 9 this doesn't work.
Please help me find the fix.
benjamin.morgan is online now   Reply With Quote


Old 01-07-2012, 07:03 PM   #2
New Member
 
*EA*Marcus's Avatar
 
Join Date: Jan 2012
Location: California
Posts: 5
Lightbulb Answer

Replace:
Quote:
if (typeof(window.event) != "undefined") {
With:
Quote:
if (oNode.attachEvent) {
That should work, it's a common problem.
__________________
Explicit Arts .NET - Superior Web Hosting and Multimedia Solutions
* 4,500 FREE Premium Templates included with ALL hosting packages
*EA*Marcus is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 05:09 PM.


Camera Forum - Computer Forum - Web Design Forum

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Content Relevant URLs by vBSEO 3.6.0 ©2011, Crawlability, Inc.