Set Default Search Engine with Javascript on iOS

July 7, 2012

The Window object in Mobile Safari on iOS has what appear to be three undocumented functions that make interaction with the default search engine possible:

window.canSetSearchEngine() window.getSearchEngine() window.setSearchEngine(string)

The Yahoo mobile search site uses these functions to throw a (very annoying) dialog box asking "Would you like to change your default search engine to Yahoo? y/n".

I haven't yet been able to make the setSearchEngine() function work because for some reason I don't have permission to do so (i.e., canSetSearchEngine() returns false).

I know the Yahoo code works so it appears that it must be possible to do. I wonder if the js file has to be hosted on a whitelisted domain related to the selected search engine. IOW - perhaps only js code served from a yahoo, google, or bing domain has permission to call the setSearchEngine() function.

Jonathan Stark is a mobile strategy consultant who believes that wireless computing will transform every aspect of society.

Jonathan is the author of three books on mobile and web development, most notably O'Reilly's Building iPhone Apps with HTML, CSS, and JavaScript which is available in seven languages.

His Jonathan's Card experiment made international headlines by combining mobile payments with social giving to create a "pay it forward" coffee movement at Starbucks locations all over the U.S.

See Jonathan in person, check out his blog, listen to his podcast (co-hosted with the incomparable @kellishaver), join the mailing list, or connect online: