If you have implemented the Context (Right click menu) options in your website. You can use the Selection of the Web API methods to get the selected text from the window.
https://developer.mozilla.org/en-US/docs/Web/API/Selection[
^]
Then you can handle the click event on the menu item using jQuery or JavaScript and create a request to the Google servers alongwith the text from websites, like this
$('#menuItem').click(function () {
window.open('http://www.google.com/search?q=' + selectedText);
});
For more on Window.Open read this document by MDN,
https://developer.mozilla.org/en-US/docs/Web/API/Window.open[
^]
Removing ambiguity
Ok, that case is really simple. Since you've already got the context, I am not going to rewrite the jQuery thing again. What you can do, is create a new page and name it "getResults.cshtml" (or the relative ASP.NET page format for your application, cshtml is a Web Pages page).
Once done, write this code to it,
var wordToSearch = Request["word"];
How to pass the word to it? You can use the following jQuery code to pass the word to the next page, instead of Google server.
$('#contextMenu').click(function () {
$.ajax({
url: '/getResults',
data: {word: selectedWord},
success: function(data) {
alert('Response from the server was: ' + data);
}
});
});
This is the code, to send the data to the server, and get the response. All using an ajax request. If you need the code to search for the contents inside the Database, read this article of mine,
How to search for related query inside the Database using ASP.NET[
^]