Can't you stop the event to avoid the page moving? If I understand what you're trying to do:
button.observe( 'click', function(event) { Event.stop(event); alert('button was clicked'); return false; } Or am I missing something? -- Jonathan Rosenberg Founder & Executive Director, Tabby's Place http://www.tabbysplace.org/ -----Original Message----- From: prototype-scriptaculous@googlegroups.com [mailto:prototype-scriptacul...@googlegroups.com] On Behalf Of JoJo Sent: Saturday, April 24, 2010 4:46 PM To: Prototype & script.aculo.us Subject: [Proto-Scripty] anchor button causes IE8 to fire onbeforeunload I'm using an anchor tag to run some JS when clicked. This works perfectly in Firefox, but Internet Explorer 8 wrongfully fires the onbeforeunload callback. I know this can be solved by changing HREF="javascript:void(0)" to HREF="#", but it won't work in my situation because my anchor is very low in the page and I don't want the page to scroll to the top when clicked. Is there any solution to get anchor-buttons to not fire onbeforeunload in IE8? ==================================== <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http:// www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <script type="text/javascript" src="http://ajax.googleapis.com/ ajax/libs/prototype/1.6.0.2/prototype.js"></script> <script type="text/javascript"> window.onbeforeunload = function() { return 'are you sure you want to leave?'; } function buttonClicked() { alert('a button was clicked'); } Event.observe( window, 'load', function() { var button = new Element( 'a', { href: 'javascript:void(0)' } ); button.observe( 'click', function() { alert('button was clicked'); return false; } ); button.update('button text'); $$('body').first().appendChild(button); } ) </script> </head> <body> </body> </html> -- You received this message because you are subscribed to the Google Groups "Prototype & script.aculo.us" group. To post to this group, send email to prototype-scriptacul...@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en. -- You received this message because you are subscribed to the Google Groups "Prototype & script.aculo.us" group. To post to this group, send email to prototype-scriptacul...@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.