I want a dictionary to open if the user clicks on any word on a webpage. It works so far:
let str = window.getSelection().toString();
window.open("https://en.thefreedictionary.com/" + str, "_blank").focus();
But now, I want that the user can select multiple words and when he double-clicks on this selection, the dictionary or a translation tool should automatically open.
On a webpage, I have the sentence “I support you as long as you need it.” If I know select “as long as” and double-click on it (say above the word long), then window.getSelection.toString()
just returns “long” and not “as long as”. So why is the selection erased by the double-click. How can I fix this?