Go Back   CodingForums.com > :: Client side development > JavaScript programming > DOM and JSON scripting

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-25-2008, 03:39 AM   PM User | #1
rptodd1
New Coder

 
Join Date: Oct 2006
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
rptodd1 is an unknown quantity at this point
Merry Christmas from IE scrooge please help

I'm writing a thumbnail image gallery and am using a ondblclick event to swap the thumbnail for a larger display. I've used both the element.setAttiute method and the element.ondblclick = syntax and neither works in IE 6 or IE 7. Both work in FireFox. Does anyone have any ideas how to set a function call in javascript that Scrouge, errr IE will honor?
rptodd1 is offline   Reply With Quote
Old 12-25-2008, 06:51 AM   PM User | #2
itsallkizza
Senior Coder

 
Join Date: Oct 2008
Location: Long Beach
Posts: 1,196
Thanks: 36
Thanked 164 Times in 164 Posts
itsallkizza will become famous soon enough
Use this for cross-browser multiple event handling:
Code:
element.addEventListener ? element.addEventListener(event,handler,false) : element.attachEvent("on"+event,handler);
Example:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Example</title>
<style type="text/css">
</style>
<script type="text/javascript">
// <![CDATA[

function dblclickHandler()
	{
	alert("hey");
	}

window.onload = function()
	{
	var my_div = document.getElementById("my_div");
	my_div.addEventListener ? my_div.addEventListener("dblclick",dblclickHandler,false) : my_div.attachEvent("ondblclick",dblclickHandler);
	}

// ]]>
</script>
</head>
<body>

<div style="background-color:#ff0000;width:300px;height:200px;text-align:center;" id="my_div">double click me</div>

</body>
</html>
__________________
Feel free to e-mail me if I forget to respond ;)
ohsosexybrit@gmail.com
itsallkizza is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 04:46 AM.


Advertisement
Log in to turn off these ads.