0

I have a chrome extension in which I have two text boxes, one for URL and other for LDAP. Whenever user clicks on extension icon, a popup page opens and I fill the URL text box with the current page URL with the help of following code:

function setValue()
{
    var text = document.getElementById("url_textbox");
    var ldap = document.getElementById("ldap_textbox");    
    chrome.tabs.getSelected(null, function(tab) {
        text.value = tab.url;
        ldap.focus();
    });
}

The statement ldap.focus() is not working here. I am calling this function on page load.

<body onload = "setValue();">

What can I do for this?

Edit : This statement get the HTML element from the document whose Id is ldap_textbox.

var ldap = document.getElementById("ldap_textbox");
Saurabh Saxena
  • 3,005
  • 10
  • 31
  • 46
  • What is the value of your ldap variable before you try to focus() ? – Jamie Dixon Feb 10 '12 at 10:11
  • What does that mean? What is in the variable? Is it undefined or is it an object? – Jamie Dixon Feb 10 '12 at 10:17
  • When you say popup page are you talking about the popup for the extensions icon and not a new tab/page? If so Im starting to think theres a bug in Chrome when it comes to focus and tab index in extensions popup. Have a look at this question.... http://stackoverflow.com/questions/9070727/tab-key-not-working-in-popup-in-chrome-extension#comment11394496_9070727 ...I might have a look through crbug.com and see if I can find anything and if not, report a bug. – PAEz Feb 11 '12 at 07:10
  • Looks like someone has posted a bug on this... http://code.google.com/p/chromium/issues/detail?id=111660 ...if you could star it, that might help it get notice. – PAEz Feb 11 '12 at 07:31

1 Answers1

0

I just found a solution for this. I needed to set focus on the ldap textbox which was below the URL textbox and for some reason, in the popup page default focus is going to the first element. So, I changed the first element to the ldap textbox. :)

<script type="text/javascript">
function setValue()
{
    var text = document.getElementById("url_textbox");
    chrome.tabs.getSelected(null, function(tab) {
        text.value = tab.url;
    });
}
</script>

<html>
    <body onload="setValue();">
        <table>
        <tr>
            <td>LDAP</td><td><input type="text" id="ldap_textbox"/></td>
        </tr>
        <tr>
            <td>URL</td><td><input type="text" id="url_textbox"/></td>
        </tr>
        </table>
     </body>
</html>
Saurabh Saxena
  • 3,005
  • 10
  • 31
  • 46