Yes, there are a couple of browser plugins which do that:
- Firefox ImTranslator and Wiktionary and Google Translate translates words and whole pages. Here is a blog post with a list of dictionary lookup plugins.
- Chrome has "search on google" it built in (via the context menu)
- Here is a list of plugins for Chrome that allow you to look up words
There are probably similar services for other browsers.
If you want to do it with JavaScript in your web page, look into the source code of the plugins. But note that allowing users to use plugins for this gives them freedom of choice: They can bring their own (preferred) tool(s).