views:

236

answers:

2

I have an ajax script with a "get more posts" button that inserts a couple screens/viewports worth of information. In doing this, the document looses focus at some point and thus the default behavior of the space bar (page down) doesn't work in firefox.

How can I focus the document again to regain the default behavior? What components control this behavior?

It works in Chrome and IE (surprisingly), but not FF.

I tried in a callback function: document.body.focus() and document.getElementById('someClickableElement').click(), but no luck.

If I actually click on the page after the content is displayed, then I can scroll again with the space bar.

Since this is a frequently used feature, it's annoying to click "load more", click again, then space to page down.

Thoughts? Suggestions?

EDIT: Ok, so i was using a YUI button (just a nice looking html "button" element with some css styling) for the interface. i replaced it with a link, and i no longer have this problem.

Interesting that it works as expected in Chrome & IE, and I'm not even using YUI listeners for the event (just the nice-looking buttons). It's handled by jquery's live method (b/c of the event delegation).

Also interesting that I'm not able to programmatically do what I can do physically (ie. "click").

Even if there is some YUI bug, it seems like firefox should be able to regain focus via some javascript action.

VERY WEIRD. Still any input appreciated (more javascript suggestions to try?). I'm somewhat committed to my current interface.

+1  A: 

I haven't tried this but how about doing a blur() on the body or the window.

window.blur();
Ólafur Waage
thanks, but no luck. it does blur the clicked button, but i still can't space down until i click somewhere in the page.
Keith Bentrup
How about a window.focus(); or body focus() ?
Ólafur Waage
body.focus() tried (part of original question) ... window.focus() no luck :(
Keith Bentrup
Oh well : S
Ólafur Waage
+1  A: 

It looks like you need to blur YUI button element. Or do something with tab order between whole document and the YUI button.

So - not to focus() document, but to blur() YUI button.

Alternatively, you may try to apply 'keypress' event simulating 'TAB' key.

Thevs
Thanks, I found this out after experimenting a bit. I was going to post my answer shortly. I'm surprised that a YUI button interferes in such a way that I have to force a blur in Firefox. I'm also surprised it's the only browser this happens in.So after I used,YAHOO.widget.Button.getButton('myelement').blur();I could page again.
Keith Bentrup
It may probably be because FF somewhat sets a different tab order. Or maybe these are some YUI specifics for FF. I'm using ExtJS, which is descendant of YUI and sometimes I have similar problems.
Thevs