Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Oct 2006
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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?

  • #2
    Senior Coder
    Join Date
    Oct 2008
    Location
    Long Beach
    Posts
    1,196
    Thanks
    36
    Thanked 164 Times in 164 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •