The mobile PC listens to the user copy content, and the pc listens to the user copy
Recently, in response to project requirements, in order to obtain information that more users want to search for, you need to obtain the content copied by users and then transmit it to the background to better understand customer needs, I have planted a big heel in this method. I only want to consider one of them, but I don't know how to use them. I am stuck in my head and write down it as soon as possible. I hope I can grow and improve slowly.
<Div class = "contenttext" oncopy = "myFunction ()"> used to test the mobile phone copy content.
Flexible use to avoid head freezing flexible use to avoid head freezing
Used to test the monitoring mobile phone copy content.
Flexible use to avoid head freezing flexible use to avoid head freezing
Used to test the monitoring mobile phone copy content.
Flexible application to avoid head freezing flexible use to avoid head freezing to test monitoring mobile phone copy content
Flexible use to avoid head freezing flexible use to avoid head freezing
</Div>
<Script> function myFunction () {var txt; txt = window. getSelection (); if (txt. toString (). length> 1) {alert ("Copied:" + txt); $. ajax ({// transfer data to the background}) }}</script>
The window. getSelection () is to obtain the selected content, detailed description see https://developer.mozilla.org/zh-CN/docs/Web/API/Window/getSelection