views:

513

answers:

4

Thi simple code below outputs two alerts instead of one Google Chrome browser. Can you tell why only in Chrome?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Can you tell?</title>
<script language="javascript" type="text/javascript">

function hitme()
{
alert('yep!');
}
</script>
</head>

<body>
<a href="#" onmouseover="hitme();">LINK</a>
</body>
</html>

Is chrome seeing the anchor as text + it's row?

What's making this double box in Chrome?

A: 

For me it's actually crashing Chrome. It happened as well when I changed it to onmouseout. What version of Chrome are you using, stable?

Rowan Parker
A: 

My first suggestion would be to try Safari this will make it clear whether the issue is specific to chrome (Eg. a chrome bug) or webkit in general (so across all webkit based browsers). It's conceivably either :D

(note for the people who have -'d this answer my assumption was that the scenario was mouseover element -> alert(), the alert is specified as being modal, so there will be no further mouse overs to the element, and i assumed dismissing the alert occurred outside of the area containing the div. In this scenario it is incorrect for two dialogs to come up, regardless of event model differences between browsers. Further Chrome is sufficiently "interesting" to make it highly possible that it has managed to mess up event handling above webkit proper, hence my suggestion it may be a chrome bug)

olliej
+4  A: 

alerting on events like mouseover is notoriously bad (read: unpredictable). mouseover event handling is great for a state change but less so for some kind of interaction like an alert.

What is likely happening is the mouseover is being fired multiple times (note mouseover is not the same as mouseenter -- note: not well supported) see http://www.quirksmode.org/js/events_mouse.html for more details on mouse events.

It's important to be aware that different browsers handle events differently. mousemove, for example, is only fired when the mouse moves in most browsers, but in firefox (if I recall correctly) it is almost constantly firing. Ditto for mouseover, and if you're really lucky, you get a stack of alert windows to close for that half second your mouse was over an element.

Jonathan Fingland
+1  A: 

I'm guessing it's something to do with window focus; if you move the mouse over the link quick enough you get only one alert box. Doesn't happen in Safari for Mac fwiw.

MSpreij