Question: In chrome browser, when using this snippet:

```
  $(document).on('keyup', function(){
    alert("Hey");
  });

```

Every time I press `enter` in the url bar (for example when I cut and paste the url of the page itself) the event listener fires.
Why does it happen?

**EDIT:**

It surprised me because url bar is not in `document` (maybe in `window`?) and firefox does not have this behaviour. When I look for `e.target`, Chrome Inspector shows `body`.

I thought this could be caused by event bubbling so I tried this:

```
  $(document).on('keyup', function(e){
    e.stopPropagation();
    alert("Hey");
  });

```

But it doesn't work.
How can I prevent it from being triggered?

Answer: 
The solution for Chrome is simple: use `keypress` instead of `keyup`. This doesn't work in all cases (IE), so you may have to add a conditional to switch the type depending on the browser. However, this will solve your issue.

Note that looking for a specific keycode may negate your issue. Good luck.
A possible solution is to slightly delay the "keyup" event handler registration. This will skip the first "spurious" trigger that seems to happen in Chrome and Safari.

```
$(function() {
    setTimeout(
        function() {
            console.log("Delayed event attachment");
            $(document).bind('keyup', log);
        }, 10);
});

function log(e) {
    console.log(e.target.localName);
}

```