Right click onpaste search

Michael Schofield mschofield at NOVA.EDU
Wed May 22 16:54:36 EDT 2013


Hey Nancy,

Unfortunately, it doesn't look like it's possible with js to add to the native context menu. You can imagine all sorts bad uses [i.e., if I were feeling evil I would replace the "Copy Link Address" function with one that downloads a trojan]. If this kind of functionality is super important, what you could do is


1.       Disable the default context menu

2.       Create a div (styled however you want) to replace it.

I would probably do something else with highlighting text.  Maybe when the user highlights text, append that text as a hidden value to a "Search!" button. You can get the highlighted text simply with window.getSelection()

var text = window.getSelection().toString();

I would definitely write in some checks to make sure you're not grabbing gibberish from an image that's been highlighted, but that's pretty much it. It's vanilla js so should work with no problem in any jquery function.

Michael Schofield
Front-End Librarian, etc. / ns4lib.com


From: Web technologies in libraries [mailto:WEB4LIB at LISTSERV.ND.EDU] On Behalf Of Nancy
Sent: Wednesday, May 22, 2013 4:25 PM
To: WEB4LIB at LISTSERV.ND.EDU
Subject: [WEB4LIB] Right click onpaste search

Is there a JavaScript or jQuery code that I can use in our search boxes that would cause a right click to give a "paste and search" or "paste and go" option the way browsers now do? ...maybe using the onpaste event?

Thank you in advance,

Nancy E. Sosna Bohm
Reference and Web Services Librarian
Lake Forest College


============================

To unsubscribe: http://bit.ly/web4lib

Web4Lib Web Site: http://web4lib.org/

2013-05-22

============================

To unsubscribe: http://bit.ly/web4lib

Web4Lib Web Site: http://web4lib.org/

2013-05-22
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listserv.nd.edu/pipermail/web4lib/attachments/20130522/e7550a2c/attachment.htm>


More information about the Web4lib mailing list