How does facebook detect when a link as been PASTED

前端 未结 8 1595
轮回少年
轮回少年 2020-12-16 04:45

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

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

8条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-16 05:16

    Listen to the keyup event in the field. If the field's content has changed by more than 1 character after one keyup, something has been pasted.

    As @epascarello points out, check right click events, too, as the user could be using the context menu.

提交回复
热议问题