...

View Full Version : Multi-site searching via one search window



Grizz
10-21-2010, 01:10 AM
Hey folks. I'm hoping someone can help with what seems like some fairly simple coding.

I'd like to create an HTML document with a "universal search box" so that I can enter my search terms, then have them inserted into the search strings for various sites, which would open in new tabs.

Kinda like this:

Search terms: "Election+coverage"

New tab #1:
http://query.nytimes.com/search/sitesearch?query=election+coverage&srchst=cse

New tab #2:
http://www.youtube.com/results?search_query=election+coverage&aq=f

So basically, after I enter my terms into the search box and hit ENTER, I need the page to take what's in that search box, insert it into several pre-defined URLs, then open each URL in a new tab.

I can't call myself a programmer by any means, though I do know some basic HTML. Is this something that would take a lot of effort to do? If not, any ideas about how to accomplish this would be much appreciated!

itsallkizza
10-21-2010, 03:44 AM
You could do something like this:



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Example</title>
<script type="text/javascript">
var sites = [
'http://query.nytimes.com/search/sitesearch?query=[QUERY]&srchst=cse',
'http://www.youtube.com/results?search_query=[QUERY]&aq=f'
];

function openQuery(q)
{
//this will only open a new tab if the user's browser is configured that way
for (var i=0;i<sites.length;i++) window.open(sites[i].replace('[QUERY]',q));
}

window.onload = function()
{
document.getElementById('submit_query_btn').onclick = function()
{
openQuery(document.getElementById('query_input').value);
};
}
</script>
</head>
<body>

<input id="query_input" type="text" />
<input id="submit_query_btn" type="button" value="query" />

</body>
</html>

Grizz
10-21-2010, 05:30 AM
Yes! That's EXACTLY what I was looking for. Thanks! :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum