Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Jun 2010
    Posts
    42
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Simple Javascript Search Engine

    Can anyone get me a simple script for a search engine for my website? i cant find a decent 1 anywhere. thanks

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,155
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    You can't write a search engine in JavaScript.

    Which is probably why you can't find a decent one.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    New Coder
    Join Date
    Jun 2010
    Posts
    42
    Thanks
    2
    Thanked 0 Times in 0 Posts
    whats the easiest way to get a search engine on my website then?

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,910
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Use Google.


    Code:
    <input type = "text" size = "40" style=" border-color:#000000;border-width:1px;"; id = "searchTerm">
    <br><br>
    <input type="button" value="Google Search" style="background-color:gold; font-weight:bold; width:180;height:30"; onclick="google()">
    <br><br>
    
    <script type = "text/javascript">
    function google() {
    var input = document.getElementById("searchTerm").value;
    if (input.length > 2) {
    var googleSearch = "http://www.google.ca/search?hl=en&source=hp&q=" + input;
    document.location.href = googleSearch;
    }
    }
    </script>
    Last edited by Philip M; 07-28-2010 at 05:30 PM.

  • #5
    New Coder
    Join Date
    Jun 2010
    Posts
    42
    Thanks
    2
    Thanked 0 Times in 0 Posts
    not what i meant. I need a search engine to search what is on my website...

  • #6
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,910
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    You might consider http://www.tesol.net/scripts/SillySearch/
    It is a Perl/cgi script which I have found very useful with a little tweaking.
    Naturally you must be able to execute cgi programs on your web server.
    Last edited by Philip M; 07-28-2010 at 07:02 PM.

  • #7
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,155
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    You can use google, but it only works if google has fully indexed your site.

    You simply specify your site's domain name as part of the search criteria.

    Use Philip's code from post #4 but just add as_sitesearch to the list of querystring arguments:
    Code:
    var googleSearch = 
        "http://www.google.com/search?hl=en&source=hp&as_sitesearch=www.yourdomainname.com&q=" + input;
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •