...

View Full Version : Merry Christmas from IE scrooge please help



rptodd1
12-25-2008, 04: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?

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


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


Example:


<!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>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum