⬆️ ⬇️

“Quote” button for iOs

When communicating on the forum, it is convenient to be able to quote phrases in your answer.

A simple script will help move the selected piece of text to the answer field.



<a href="javascript://" onClick="document.getElementById('message').value = window.getSelection().toString();"></a> 


demo



For iOS


In mobile Safari, such a selection does not work - the text selection is reset a little earlier than the click on quote event.

')

It is necessary to keep the selection and regularly update the data:



 var selectedRange = null; selectedRangeID = setInterval(getSelectedRange, 150); function getSelectedRange() { try { if (window.getSelection) { selectedRange = window.getSelection().toString(); } else { if (document.selection) { // Internet Explorer selectedRange = document.selection.createRange().text; } else { selectedRange = document.getSelection(); } } } catch (err) { } }; 


demo 2



Then when you click on the "quote" we will query the contents of the selectedRange variable and get the selection.



The script works correctly on disk browsers and on the iPad.

Not tested on Android tablets.

Source: https://habr.com/ru/post/161867/



All Articles