Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It's possible and I've posted code to create a range from a mouse event on Stack Overflow before:</p> <p><a href="https://stackoverflow.com/a/12924488/96100">https://stackoverflow.com/a/12924488/96100</a></p> <p>Here's a demo that allows selection with the right mouse button:</p> <p><a href="http://jsfiddle.net/timdown/BpjyG/6/" rel="nofollow noreferrer">http://jsfiddle.net/timdown/BpjyG/6/</a></p> <p>It includes code from the linked answer plus the following:</p> <pre><code>var anchorRange; function mouseMove(evt) { evt = evt || window.event; var range = getMouseEventCaretRange(evt), sel, selRange; if (typeof range.setEndPoint != "undefined") { // Old IE selRange = anchorRange.duplicate(); selRange.setEndPoint("EndToEnd", range); if (selRange.text == "") { // Try the other way round selRange = anchorRange.duplicate(); selRange.setEndPoint("StartToStart", range); } selRange.select(); } else if (window.getSelection) { sel = window.getSelection(); if (sel.extend) { // This is ideal: we can create forwards and backwards selections // simply by moving the focus using extend() sel.extend(range.startContainer, range.startOffset); } else { // We'll need to create a range and test for backwardsness selRange = document.createRange(); selRange.setStart(sel.anchorNode, sel.anchorOffset); selRange.setEnd(range.startContainer, range.startOffset); if (selRange.collapsed) { // Try the other way roound selRange.setStart(range.startContainer, range.startOffset); selRange.setEnd(sel.anchorNode, sel.anchorOffset); } selectRange(selRange); } } } function mouseUp(evt) { evt = evt || window.event; if (evt.button == 2) { if (document.releaseCapture) { document.releaseCapture(); } document.onmousemove = null; document.onmouseup = null; anchorRange = null; } } document.oncontextmenu = function() { return false; }; document.onmousedown = function(evt) { evt = evt || window.event; if (evt.button == 2) { rightMouseButtonDown = true; var range = getMouseEventCaretRange(evt); anchorRange = range; selectRange(range); if (document.body.setCapture) { document.body.setCapture(); } document.onmousemove = mouseMove; document.onmouseup = mouseUp; return false; } }; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload