View Full Version : Merry Christmas from IE scrooge please help

12-25-2008, 03:39 AM
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?

12-25-2008, 06:51 AM
Use this for cross-browser multiple event handling:

element.addEventListener ? element.addEventListener(event,handler,false) : element.attachEvent("on"+event,handler);


<!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">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style type="text/css">
<script type="text/javascript">
// <![CDATA[

function dblclickHandler()

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

// ]]>

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