Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Local jawascript search to search pages from only my website

Reply
Thread Tools

Local jawascript search to search pages from only my website

 
 
manish
Guest
Posts: n/a
 
      11-08-2008
HI
I want a jawascript that will search pages from only my subdomain
website eg. abc.efg.com
can anyone help me
please give the exact jawascript as I am not an expert programmer
please if possible email it to http://www.velocityreviews.com/forums/(E-Mail Removed)
awaiting
Manish wagh
 
Reply With Quote
 
 
 
 
rf
Guest
Posts: n/a
 
      11-08-2008

"manish" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> HI
> I want a jawascript that will search pages from only my subdomain
> website eg. abc.efg.com
> can anyone help me
> please give the exact jawascript as I am not an expert programmer


How is that going to help? Your Javascript lives on one single page. All the
other pages that need to be searched live on your host. Whatever you do you
will need a server side solution.

> please if possible email it to (E-Mail Removed)


Nope.


 
Reply With Quote
 
 
 
 
Bart Van der Donck
Guest
Posts: n/a
 
      11-08-2008
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.getElementById('results').innerHTML = '';
document.getElementById('restitle').innerHTML =
'<h3>Search results for \'<i>' + q + '<\/i>\'<\/h3>\n';
for (var i=0; i<pages.length; i++) fetch(pages[i], q);
if (document.getElementById('results').innerHTML == '') {
document.getElementById('results').innerHTML = 'No results';
}
}

function fetch(page, q) {
xhr = null;
if (window.XMLHttpRequest) {
xhr = new XMLHttpRequest();
}
else if (window.ActiveXObject) {
xhr = new ActiveXObject('Microsoft.XMLHTTP');
}
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.responseText))
document.getElementById('results').innerHTML +=
'<a target="_blank" href="'+page+'">'+page+'<\/a><br>
\n';
}
}
}
}
</script>
</head>
<body>
<form action="#"
onSubmit="do_srch(document.forms[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>Apples are great! \</body></html>
5.htm: <html><body>two 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
 
Reply With Quote
 
Mike Duffy
Guest
Posts: n/a
 
      11-08-2008
Bart Van der Donck <(E-Mail Removed)> wrote in news:567bf9f1-aa40-44ff-8781-
(E-Mail Removed):

> ....
> xhr = new ActiveXObject('Microsoft.XMLHTTP');


> ....
> http://groups.google.com/group/comp....f704292a72a661


Will these methods work with non-MS browsers?
 
Reply With Quote
 
Gregor Kofler
Guest
Posts: n/a
 
      11-08-2008
Mike Duffy meinte:
> Bart Van der Donck <(E-Mail Removed)> wrote in news:567bf9f1-aa40-44ff-8781-
> (E-Mail Removed):
>
>> ....
>> xhr = new ActiveXObject('Microsoft.XMLHTTP');

>
>> ....
>> http://groups.google.com/group/comp....f704292a72a661

>
> Will these methods work with non-MS browsers?



If properly coded - yes.

Gregor
 
Reply With Quote
 
Bart Van der Donck
Guest
Posts: n/a
 
      11-08-2008
Mike Duffy wrote:

> Bart Van der Donck <(E-Mail Removed)> wrote in news:567bf9f1-aa40-44ff-
> (E-Mail Removed):
>
>> ....
>> * *xhr = new ActiveXObject('Microsoft.XMLHTTP');
>> ....


> Will these methods work with non-MS browsers?


Non-Microsoft browsers should support window.XMLHttpRequest. The
ActiveXObject call is for backwards compatibility with MSIE <7.

http://en.wikipedia.org/wiki/XMLHttp...ry_and_support

"The XMLHttpRequest concept was originally developed by
Microsoft [...] It has been available since the introduction
of Internet Explorer 5.0* [...] Internet Explorer versions prior
to 7.0 require XMLHTTP to be invoked as an ActiveXObject [...]
The Mozilla project incorporated the first compatible native
implementation of XMLHttpRequest in Mozilla 1.0 in 2002. This
implementation was later followed by Apple since Safari 1.2,
Konqueror, Opera Software since Opera 8.0, iCab since 3.0b352,
and Microsoft since Internet Explorer 7.0."

* = March 1999
see http://en.wikipedia.org/wiki/Internet_Explorer_5

--
Bart
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Good Website Search Engines Besides Google Search ... Chris K. HTML 3 06-08-2008 05:46 AM
.NET 2.0: Sending email on local domain to local exchange 2K server Jim in Arizona ASP .Net 8 01-24-2006 05:37 PM
Access local port or Running local exe file =?Utf-8?B?WVNVVA==?= ASP .Net 0 01-14-2006 12:41 AM
Search only the page (need search of value of textboxes as well) sancha Javascript 0 08-05-2005 09:13 AM
Can't use 'local' to find sql server instances on local machine karim ASP .Net 1 06-26-2003 09:17 PM



Advertisments