Disable Automatic URL detection for Elements with 'contentEditable' flag in IE
Asked Answered
T

4

6

When i paste any text in any element with 'contentEditable' flag enabled, IE automatically finds the hyperlinks or email address and replaces them with

<a href="hyperlink">hyperlink</a>.

How can i disable this automatic url detection for elements(e.g. div, span etc.) with 'contentEditable' flag in IE or aleast get the actual text that was pasted in the div.

Best Regards,
Keshav

Toplevel answered 19/8, 2010 at 7:34 Comment(0)
A
1

I don't think you can. You'll need catch the paste event and set a brief timer that calls a function that removes links.

Edit 30 September 2012

IE 9 and above has the ability to switch this off. See Maxon's answer.

Armipotent answered 19/8, 2010 at 8:2 Comment(0)
A
4

Unfortunately, there is no cross-version solution. In IE9 there is opportunity, allowing to disable automatic hyperlinking:

document.execCommand("AutoUrlDetect", false, false);

More information: http://msdn.microsoft.com, http://bytes.com

Almemar answered 27/9, 2011 at 12:17 Comment(0)
A
1

I don't think you can. You'll need catch the paste event and set a brief timer that calls a function that removes links.

Edit 30 September 2012

IE 9 and above has the ability to switch this off. See Maxon's answer.

Armipotent answered 19/8, 2010 at 8:2 Comment(0)
K
0

I use preventDefault on space key, enter key, tab key's keydown event to prevent URL detection. Tested on IE11 and Chrome.

document.getElementById("input").addEventListener("keydown", function (e) {
  var SPACEKEY = 32;
  var ENTERKEY = 13;
  var TABKEY = 9;

  var whiteSpace = "";

  if (e.keyCode == SPACEKEY || e.keyCode == ENTERKEY || e.keyCode == TABKEY) {
    e.preventDefault();

    if (e.keyCode == SPACEKEY) {
      whiteSpace = " ";
    } else if (e.keyCode == ENTERKEY) {
      whiteSpace = "\n";
    } else if (e.keyCode == TABKEY) {
      whiteSpace = "\t";
    }

    var selection = document.getSelection();
    var start = selection.anchorOffset > selection.focusOffset ? selection.focusOffset : selection.anchorOffset;
    var end = selection.anchorOffset > selection.focusOffset ? selection.anchorOffset : selection.focusOffset;

    $(this).text($(this).text().substring(0, start)
      + " "
      + $(this).text().substring(end));
    var range = document.createRange();
    range.setStart($(this)[0].firstChild, start + 1);
    range.setEnd($(this)[0].firstChild, start + 1);
    selection.removeAllRanges();
    selection.addRange(range);
  }
  return false;
});
Kippie answered 7/4, 2017 at 14:43 Comment(0)
U
0

It seems that it works for Chrome: Hold Ctrl+Alt to disable the links temporarily. This extension disables links when you hold Ctrl+Alt. This allows to select text from the middle of the link, and generally eases selection, eliminating the risk to click the link while copying it.

Ulla answered 21/12, 2021 at 21:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.