简体   繁体   中英

How to select a text in the HTML page only?

I need to show the selected text into popup window, okay, I created the popup window and added event handler, for example.

$("body").on("click", function(){
    var selectedText = window.getSelection().toString() ;
    myPopupWindow.show(selectedText) ;
})

And then I show the text into the popup window, but when I select a text into the popup window it appears again, but I don't want to appear it again when popup is showing.

add an if statement to check the visibility of your popup:

$("body").on("click", function() {
    if ($("#popup").css("display") == "none") {
        var selectedText = window.getSelection().toString() ;
        myPopupWindow.show(selectedText);
    }
})

将$(“ body”)更改为更具体的内容,例如仅包含Web内容的容器div,因此在弹出窗口中选择文本不会触发相同的操作。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM