facebook如何在链接被检测时检测到

Dav*_*och 6 javascript jquery facebook

Facebook的状态更新输入(嗯,contenteditable div)检测链接.

键入链接时,它会等到按下空格键后才能获取URL.

粘贴链接时,它会立即获取URL.

我可以在按下空格键后解析URL ...但我不确定何时检测内容被粘贴.

任何解决方案都会很棒; 一个jQuery格式的解决方案将是最好的!

epa*_*llo 10

现代浏览器支持onpaste:

<!DOCTYPE html>
<html>
<head>
<title>onpaste event example</title>
</head>

<body>
<h1>Play with this editor!</h1>
<textarea id="editor" rows="3" cols="80">
Try pasting text into this area!
</textarea>

<script>
function log(txt) {
  document.getElementById("log").appendChild(document.createTextNode(txt + "\n"));
}

function pasteIntercept(evt) {
  log("Pasting!");
}

document.getElementById("editor").addEventListener("paste", pasteIntercept, false);
</script>

<h2>Log</h2>
<textarea rows="15" cols="80" id="log" readonly="true"></textarea>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

  • 然而,在粘贴发生之前调用onpaste.因此,必须设置一些标记用于粘贴,而不是调用onchange (3认同)