manish wrote:
I want a jawascript that will search pages from only my subdomain
website eg. abc.efg.com
----------------------------------------------------------------
START CODE
----------------------------------------------------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<head>
<title>Search </title>
<script type="text/javascript">
var xhr;
var pages = ['1.htm', '2.htm', '3.htm', '4.htm', '5.htm'];
function do_srch(q) {
document.getEle mentById('resul ts').innerHTML = '';
document.getEle mentById('resti tle').innerHTML =
'<h3>Search results for \'<i>' + q + '<\/i>\'<\/h3>\n';
for (var i=0; i<pages.length ; i++) fetch(pages[i], q);
if (document.getEl ementById('resu lts').innerHTML == '') {
document.getEle mentById('resul ts').innerHTML = 'No results';
}
}
function fetch(page, q) {
xhr = null;
if (window.XMLHttp Request) {
xhr = new XMLHttpRequest( );
}
else if (window.ActiveX Object) {
xhr = new ActiveXObject(' Microsoft.XMLHT TP');
}
if (xhr != null) {
xhr.open('GET', page +'?' + (new Date()).getTime (), false);
xhr.send(null);
if (xhr.readyState == 4) {
if (xhr.status == 200) {
q = q.replace(
/(\\|\^|\$|\*|\+ |\?|\.|\{|\}|\( |\)|\:|\=|\!|\| |\,|\[|\])/g,
'\\$1');
if ((new RegExp(q)).test (xhr.responseTe xt))
document.getEle mentById('resul ts').innerHTML +=
'<a target="_blank" href="'+page+'" >'+page+'<\/a><br>
\n';
}
}
}
}
</script>
</head>
<body>
<form action="#"
onSubmit="do_sr ch(document.for ms[0].q.value); return false;">
<input size="40" type="text" name="q" value="apple">
<input type="submit" value="Search">
</form>
<div id="restitle"> </div>
<div id="results"></div>
</body>
</html>
----------------------------------------------------------------
END CODE
----------------------------------------------------------------
And the following pages to search:
1.htm: <html><body>2 apples and 1 pear</body></html>
2.htm: <html><body>3 oranges and 1 kiwi *</body></html>
3.htm: <html><body>4 pears and 1 app
le</body></html>
4.htm: <html><body>App les are great! \</body></html>
5.htm: <html><body>t wo apples</body></html>
See the direct demo at:
http://www.dotinternet.be/temp/xhr_src/xhr_src.htm
All files need to be placed on your same subdomain 'abc.efg.com'.
Wildcards are not allowed in the search queries. The search is case-
sensitive.
This demo works with defined files that are to be searched (see the
'pages'-variable). If you want XMLHttpRequest to search all files in a
directory, then you could do something like
http://groups.google.com/group/comp....f704292a72a661
Hope this helps,
--
Bart