当一个链接被PASTED时,Facebook如何检测 [英] How does facebook detect when a link as been PASTED

查看:98
本文介绍了当一个链接被PASTED时,Facebook如何检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Facebook's status update input (well, contenteditable div) detects links.

当输入链接时,等待直到空格键被抓取才能获取URL。

When typing a link it waits until the spacebar is pressed before fetching the URL.

当粘贴链接时,它会立即获取该URL。

When pasting a link it fetches the URL instantly.

我可以在空格键被压缩后解析URL。但是我不知道检测内容是否被粘贴。

I can already parse the url after the spacebar is pressed...but I'm not sure about detecting when content is pasted.

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

Any solution would be awesome; a jQuery formatted solution will be BEST!

推荐答案

现代浏览器支持 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>

这篇关于当一个链接被PASTED时,Facebook如何检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆