I am developing an HTML page that I want to convert in Search Engine.
I just have put a Textbox & Search Button. I am just allowed to use JavaScript. How do I convert it in Search Engine ?
I am developing an HTML page that I want to convert in Search Engine.
I just have put a Textbox & Search Button. I am just allowed to use JavaScript. How do I convert it in Search Engine ?
You could use JavaScript to redirect the user to another search-engine.
For instance you could simply take the user input from the text box and do a JavaScript redirect to http://www.google.com/search?q=$user_input
where $user_input
is the value of your form.
Writing a whole search-engine in JavaScript would simply be impossible.
You could achieve the same thing without using JavaScript by giving the form input name="q" and changing its action to http://google.com. Bringing JavaScript into the equation to do something so simple doesn't add any benefit to the user, and will lock out users without JavaScript from the functionality.
You can use any search engine like google.com or bing.com to fetch the data. You can write your jquery script to send the input form data to any of the search engine and display the result in the same page.
<html>
<head><title>search engine</title>
<script type="text/javascript" src="jQuery.js"/>
<script type="text/javascript" src="search.js"/>
</head>
<body>
<div id="searchContainer">
<form id="searchForm">
<input id="searchbox" name="q" type="text"/>
<button id="searchbutton" type="submit" value="search"/>
</form>
</div>
<div id="result"></div>
</body>
</html>
Following is the search.js file:
(function($){
var googleUrl = "http://www.google.com?";
function fetchAndInsertResults(inputText){
$.ajax({
url: googleUrl+inputText,
success: function(data){
$('#result').html(data);
}
});
}
$('#searchbutton').bind('submit',function(){
this.preventDefault();
var inputText = $('#searchForm').serialize();
fetchAndInsertResults(inputText);
});
})(jQuery);