One of the tips here is how to use JavaScript to get the selected text on the page. The most critical JavaScript APIs are:
Event= Window. GetSelection();
This selection
is actually an object, but if we use it .toString()
or force it into a string, we will get the selected text.
$ (document). Ready (function () {$ (". ContentText"). MouseUp (function (e) {var Txt;var parentoffset = $ (this). offset (); var x = E.pagex-parentoffset.left;var y = E.pagey-parentoffset.top;txt = Window.getselection (); if (txt.toString (). Length & Gt 1) {alert (TXT);});});
If we put this piece of code on the following page:
>><title>get selected text with JavaScript</title><metaCharSet="UTF-8"><metaName="Viewport"Content=The width=device-width, Initial-scale=1.0"><scriptSrc="Http://www.webhek.com/wordpress/wp-includes/js/jquery/jquery.js"Type="Text/javascript"></script>><body><divclass= "Contenttext" > and the client's JavaScript is different, PHP code is running on the server side. If you set up code similar to the example above on your server, the client will be able to receive the results after running the script, but they will not know how the code behind it works. You can even set the WEB server to allow PHP to process all the HTML files, so that the user doesn't know what the servers are doing. One of the great benefits of using PHP is that it is simple for beginners and provides a variety of advanced features for professional programmers. Don't be afraid when you see a long list of features in PHP. You can get started quickly and you can write some simple scripts yourself in a few hours. </div > </body>>
When you use the mouse to select some of the text in the page, and you get the selected content, I am here to use the alert()
method to display it.
Watch the demo watch demo from: Http://www.webhek.com/get-selected-text-with-javascript
Tips for getting selected text on a page with JavaScript