Created
November 20, 2017 14:02
-
-
Save Kilerd/281c0cc80c18e0ce698f4e670c5522f8 to your computer and use it in GitHub Desktop.
inline translator.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// get the text selected | |
if(window.getSelection) {//一般浏览器 | |
userSelection = window.getSelection();} | |
else if(document.selection) {//IE浏览器、Opera | |
userSelection = document.selection.createRange(); | |
} | |
// get text | |
text = userSelection.baseNode.data | |
// get parent node | |
parent = userSelection.extentNode.parentElement | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment