Windows only: focus() on an input field in popup.html

912 views
Skip to first unread message

elsigh

unread,
Feb 19, 2010, 6:13:01 PM2/19/10
to Chromium-extensions
In our popup.html we have a <input id="foo" type="text">
and we call a function when the body onload event occurs which has a
line: document.getElementById('foo').focus();
This works correctly in Chrome Linux and Mac, but not in Windows.
I've tried various tricks(different ways of hooking the event,
setTimeout(focusFunction, 0) to get it to work and had no luck.

dabear

unread,
Feb 20, 2010, 9:32:51 AM2/20/10
to Chromium-extensions
Hi. Have you .select()-ed the input first?

elsigh

unread,
Feb 21, 2010, 2:44:24 AM2/21/10
to Chromium-extensions
You don't need to select() in order to focus() do you?
In fact, if I simply load the page via chrome-extension://myid/
popup.html in Windows Chrome, I can see that my text input does in
fact get focused.
It's only in the case that it's in the pageAction popup.

Pedro Junior

unread,
Feb 21, 2010, 10:34:10 AM2/21/10
to elsigh, Chromium-extensions
You tested with textarea?

In my extension work normal with textarea.



Pedro Junior

 

 

2010/2/21 elsigh <els...@gmail.com>
--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.
For more options, visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/?hl=en.


Lindsey Simon

unread,
Feb 22, 2010, 11:53:56 AM2/22/10
to Paul Kinlan, Chromium-extensions
Ah, cool, very good to know about. I added that to my popup.html, and even completely removed my javascript from the page, but when the popup loads in windows, the text input still does not get focused.
It is a simple form with just a text input and a submit button.
Thanks

On Sun, Feb 21, 2010 at 2:47 PM, Paul Kinlan <paulk...@chromium.org> wrote:
Hi,

There is an autofocus HTML5 attribute that you can use in Chrome which means that you do not have to resort to javascript.

For example:
<input name="q" type="text" autofocus>

Kind Regards
Paul

Paul Kinlan

unread,
Feb 21, 2010, 5:47:47 PM2/21/10
to elsigh, Chromium-extensions
Hi,

There is an autofocus HTML5 attribute that you can use in Chrome which means that you do not have to resort to javascript.

For example:
<input name="q" type="text" autofocus>

Kind Regards
Paul

On Fri, Feb 19, 2010 at 3:13 PM, elsigh <els...@gmail.com> wrote:

Paul Kinlan

unread,
Feb 22, 2010, 1:32:42 PM2/22/10
to Chromium-extensions
Hi,

I have just tested autofocus on a couple of devices (namely a mac and a windows machine 4.0.249.89) and all seems well. The example had two input boxes inside a form and requested that the second input box be autofocused.

I have attached the sample I created so you can check against that to see if it works on your windows box.  I think this example replicates what you are after.

If this works and your code still doesn't would you be able to provide us with a minimal example of your problem and the version number of Chrome that it does not work on.

Thanks,
Paul Kinlan
autofocus 2.zip

Adam S

unread,
Feb 24, 2010, 3:12:36 AM2/24/10
to Chromium-extensions
Hi Paul,

I work with the author of this thread. What we've observed is that
auto-focus doesn't work in **page actions**. Your example uses browser
actions, which is why it works. I'm unable to attach files to this
post via the web interface, but please try the following and you'll
see this bug in action.

manifest.json:
----------------------
{
"name": "TestAutofocus",
"version" : "1.0.0.0",
"background_page": "background.html",
"page_action": {
"default_icon": "test.png",
"default_title": "Testing Autofocus",
"popup": "popup.html"
},
"permissions": [
"tabs"
]
}

background.html:
----------------------
<html>
<body>
<script type="text/javascript" src="background.js"></script>
</body>
</html>

background.js:
----------------------
chrome.windows.getAll({'populate': true}, function(windows) {
for (var i = 0, window; window = windows[i]; i++) {
for (var j = 0, tab; tab = window.tabs[j]; j++) {
chrome.pageAction.show(tab.id);
}
}
});

popup.html:
----------------------
<html>
<body>
<form>
<input type="text" autofocus>
</form>
</body>
</html>


Thanks,
Adam

On Feb 22, 10:32 am, Paul Kinlan <paulkin...@chromium.org> wrote:
> Hi,
>
> I have just tested autofocus on a couple of devices (namely a mac and a
> windows machine 4.0.249.89) and all seems well. The example had two input
> boxes inside a form and requested that the second input box be autofocused.
>
> I have attached the sample I created so you can check against that to see if
> it works on your windows box.  I think this example replicates what you are
> after.
>
> If this works and your code still doesn't would you be able to provide us
> with a minimal example of your problem and the version number of Chrome that
> it does not work on.
>
> Thanks,
> Paul Kinlan
>
>
>
> On Mon, Feb 22, 2010 at 8:53 AM, Lindsey Simon <lsi...@commoner.com> wrote:
> > Ah, cool, very good to know about. I added that to my popup.html, and even
> > completely removed my javascript from the page, but when the popup loads in
> > windows, the text input still does not get focused.
> > It is a simple form with just a text input and a submit button.
> > Thanks
>

> > On Sun, Feb 21, 2010 at 2:47 PM, Paul Kinlan <paulkin...@chromium.org>wrote:
>
> >> Hi,
>
> >> There is an autofocus HTML5 attribute that you can use in Chrome which
> >> means that you do not have to resort to javascript.
>
> >> For example:
> >> <input name="q" type="text" autofocus>
>
> >> Kind Regards
> >> Paul
>
> >> On Fri, Feb 19, 2010 at 3:13 PM, elsigh <els...@gmail.com> wrote:
>
> >>> In our popup.html we have a <input id="foo" type="text">
> >>> and we call a function when the body onload event occurs which has a
> >>> line: document.getElementById('foo').focus();
> >>> This works correctly in Chrome Linux and Mac, but not in Windows.
> >>> I've tried various tricks(different ways of hooking the event,
> >>> setTimeout(focusFunction, 0) to get it to work and had no luck.
>
> >>> --
> >>> You received this message because you are subscribed to the Google Groups
> >>> "Chromium-extensions" group.

> >>> To post to this group, send email to chromium-extensi...@chromium.org.


> >>> To unsubscribe from this group, send email to

> >>> chromium-extensions+unsubscr...@chromium.org<chromium-extensions%2Bunsubscr...@chromium.org>


> >>> .
> >>> For more options, visit this group at
> >>>http://groups.google.com/a/chromium.org/group/chromium-extensions/?hl=en
> >>> .
>

> >  --
> > You received this message because you are subscribed to the Google Groups
> > "Chromium-extensions" group.

> > To post to this group, send email to chromium-extensi...@chromium.org.


> > To unsubscribe from this group, send email to

> > chromium-extensions+unsubscr...@chromium.org<chromium-extensions%2Bunsubscr...@chromium.org>


> > .
> > For more options, visit this group at
> >http://groups.google.com/a/chromium.org/group/chromium-extensions/?hl=en.
>
>
>

>  autofocus 2.zip
> 1KViewDownload

Paul Kinlan

unread,
Feb 25, 2010, 1:40:55 PM2/25/10
to Chromium-extensions
Hi Adam,

Thanks for the clarification, and the example case.  You are correct, it does not work on page actions in windows (although it is fine on the mac and linux).

A bug has been raised (http://code.google.com/p/chromium/issues/detail?id=36646) you can star this item to get notification of changes to the issue.

Kind Regards,
Paul Kinlan

To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.
Reply all
Reply to author
Forward
0 new messages