I have tried to insert this code [...] but nothing happens when I invoke it.
When you use a search engine from the omnibox, it just transforms the query string into an URL. That works well with actual URLs, but it can fail with javascript:
.
You will be able to use this custom search if you're in a tab displaying a normal website, but not if you're looking at the New Tab or Settings page, for example. The reason is that Chrome disables javascript:
URLs in any form (direct invocation from omnibox, custom search, bookmark, etc.) for the internal chrome://
pages (source).
This is done for security reasons, since these pages often contain sensitive information (e.g., New Tab contains links to the most visited websites), and JavaScript could access and divulge that information.
Is it possible to get this to work this way or another in Chrome? I would prefer to achieve this without extensions.
I don't think that there's a straightforward way of achieving this, as any attempt to automatically open several tabs from a common HTML page will result in several new windows (unless this is desired).
The best way to solve this would probably be an extension.
Further options:
Keep using your existing approach.
Just make sure you don't open a new tab before you search. Since your custom search doesn't modify the existing tab, you might get used to that.
"Extend" your search with a bookmark.
Leave Google (for example) as your default search and create the following bookmark:
Name: Extend Google search
URL: javascript:var q=document.location.search.match(/[?&][pq]=(.*?)(&|$)/)[1];window.open('http://www.altavista.com/web/results?q='+q);window.open('http://www.bing.com/search?q='+q);void(0)
Clicking the bookmark after performing a Google search will search in all other engines.