如何实现在asp.net中搜索所选文本,就像谷歌一样,bing有 [英] How to implement searching for selected text in asp.net like the one google, bing has

查看:60
本文介绍了如何实现在asp.net中搜索所选文本,就像谷歌一样,bing有的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。



我正在asp.net网站上工作,我想在那里实现搜索,虽然搜索部分已经完成,我想实现添加功能以突出显示文本,右键单击右键单击上下文菜单中的文本,并相应地搜索谷歌的Chrome浏览器和IE浏览器中的文件。



我已经制作了一个定制的右键菜单,并希望在其中实现上述内容。



请帮助



谢谢



很抱歉这个混乱,我想我不清楚我的问题,

我已经链接了一个图像我希望在我的网络应用程序中实现 [ ^ ]。

我想在我的网络应用程序中实现数据库驱动的搜索(不是谷歌搜索)



谢谢

解决方案

Google搜索API:

https://developers.google.com/custom-search [ ^ ],

https://developers.google.com/app-indexing [ ^ ]。



Bing搜索API:

http://www.bing.com/developers/s/APIBasics.html [ ^ ],

http://www.bing.com/toolbox/bingsearchapi [ ^ ]。



如果您打算不使用此类服务​​,可能虽然关于你自己的搜索引擎。欢迎您开发您的搜索技术,但您需要了解:像Google和Binge这样的搜索引擎有他们的索引,一种互联网,其形式是从互联网收集的大量数据并编入索引,定期更新基础。这听起来真实吗? :-)



-SA


如果您已实现了Context(右键菜单)您网站上的选项。您可以使用选择Web API方法从窗口中获取所选文本。



https:// developer。 mozilla.org/en-US/docs/Web/API/Selection [ ^ ]



然后你可以使用jQuery或JavaScript处理菜单项上的click事件并创建一个请求与来自网站的文本一起到谷歌服务器,比如这个



 


' #menuItem')。click( function ( ){
// selectedText是选择保留值
window .open(' http://www.google.com / search?q =' + selectedText);
});





有关Window.Open的更多信息,请通过MDN阅读本文档, https://developer.mozilla.org/en-US/docs/Web/API/Window.open [ ^ ]



消除歧义



好​​的,那个案子很简单。既然你已经有了上下文,我就不会再重写jQuery了。您可以做的是创建一个新页面并将其命名为getResults.cshtml(或者您的应用程序的相对ASP.NET页面格式,cshtml是一个Web页面页面)。



完成后,将此代码写入其中,

  var  wordToSearch = Request [  word]; 

// 初始化数据库连接
// 搜索其中的相对内容,

// 返回结果(这将传递给客户端)





如何传递这个词?您可以使用以下jQuery代码将该单词传递到下一页,而不是Google服务器。



 


Hi everyone.

I am working on a asp.net web site, where I want to implement search, although the searching part is done, I wanted to implement an added functionality to highlight a text and on right click get the text on the right click context menu and accordingly search which google has with its chrome browser and bing in IE.

I have made a customized right click menu and wish to implement the above in it.

Please help

Thank You

Sorry for the confusion, I guess I was not clear with my question,
I have linked an image of what I wish to implement in my web application [^].
I want to implement a database driven search within my web application (not Google search)

Thank you

解决方案

Google search API:
https://developers.google.com/custom-search[^],
https://developers.google.com/app-indexing[^].

Bing search API:
http://www.bing.com/developers/s/APIBasics.html[^],
http://www.bing.com/toolbox/bingsearchapi[^].

If your meant not to use such services, you probably though about your own search engine. You are welcome to develop your search technology, but you need to understand: search engines like Google and Binge have their index, a kind of "second internet" in the form of a huge volume of data collected from Internet and indexed, updated on regular basis. Does it sound realistic to you? :-)

—SA


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 () { // selectedText is the variable holding value from Selection 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"];

//initialize the Database connection
// search for the relative content in it, 

// return the results (this will be passed down to the client)



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.


这篇关于如何实现在asp.net中搜索所选文本,就像谷歌一样,bing有的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆