Created
July 3, 2012 01:05
-
-
Save ttscoff/3036750 to your computer and use it in GitHub Desktop.
Bookmarklet to select the search field on the current page and focus it
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript:var%20inputs=document.getElementsByTagName('input'),firstSearch=false,textinputs=[],i,t;for(i=0;i<inputs.length;i++)if(((inputs[i].type==='text')||(inputs[i].type==='search'))&&inputs.disabled!==true)textinputs.push(inputs[i]);for(t=0;t<textinputs.length;t++)if((/search/i).test(textinputs[t].className)||(/(^[sq]$|search|query)/i).test(textinputs[t].id)||(/^(q(uery)?|s|.*?search.*)$/).test(textinputs[t].name)){firstSearch=textinputs[t];break;}if(!firstSearch)textinputs[0].focus();else%20firstSearch.focus(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// searchFocus pre-bookmarkleting | |
var inputs = document.getElementsByTagName('input'), | |
firstSearch = false, | |
textinputs = [], | |
i,t; | |
for(i=0;i<inputs.length;i++) | |
if (((inputs[i].type === 'text') || (inputs[i].type === 'search')) && inputs.disabled !== true) textinputs.push(inputs[i]); | |
for (t=0;t<textinputs.length;t++) | |
if ((/search/i).test(textinputs[t].className) || (/(^[sq]$|search|query)/i).test(textinputs[t].id) || (/^(q(uery)?|s|.*?search.*)$/).test(textinputs[t].name)) { firstSearch = textinputs[t]; break;} | |
if (!firstSearch) | |
textinputs[0].focus().select(); | |
else | |
firstSearch.focus().select(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment