JavaScript警报消息

时间:2018-05-05 12:15:19

标签: javascript alert

我不确定,当有人尝试使用JavaScript从网页复制文字时,是否可以显示提醒消息?如果可能的话,我该怎么做?

如果您有任何想法,请提出建议。

2 个答案:

答案 0 :(得分:5)

这样的事可能吗?



func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: 
"cellID", for: indexPath) as! PageCellCollectionViewCell
    let page = pages[indexPath.item]
    cell.page = page
    return cell
}




答案 1 :(得分:-4)

基本上你可以在这里检测按下ctrl + c和ctrl + v的按键,并在触发这些按键事件时发出警报

var code = (document.all) ? event.keyCode:e.which;
var ctrl = (document.all) ? event.ctrlKey:e.modifiers & Event.CONTROL_MASK;
var msg = "Sorry, this functionality is disabled.";
if (ctrl && code==86) //CTRL+V
{
alert(msg);
window.event.returnValue = false;
}
else if (ctrl && code==67) //CTRL+C (Copy)
{
alert(msg);
window.event.returnValue = false;
}

确保上下文菜单也被

禁用
onpaste="return false;" oncut="return false;" oncontextmenu="return false;" oncopy="return false;"
相关问题