大家一定遇到过网页内容无法复制的问题,虽然实现技术简单,但碰到时还真是挺烦人的,现在偶提供一个最迅速的解决方案,就是在浏览器地址栏输入以下代码:
javascript:alert(document.onselectstart
=
document.oncontextmenu
=
document.onmousedown
=
document.onkeydown
=
function
(){
return
true
;});
嘿嘿,是不是可以选中内容可以复制了?神奇吧!
首先了解下常见的实现无法复制内容的javascript技术,如下:
(1)屏蔽选中事件
document.onselectstart
=
function
(){
return
false
;}
(2)屏蔽右键菜单
document.oncontextmenu
=
function
(){
return
false
;}
(3)另一种屏蔽右键菜单
document.onmousedown
=
function
(){
if
(event.button
==
2
)
return
false
;}
(4)屏蔽ctrl按键
document.onkeydown
=
function
(){
if
(event.ctrlKey)
return
false
;}
了解了上述原理,要屏蔽就易如反掌了,呵呵,在浏览器输入如下代码:
javascript:alert(document.onselectstart
=
document.oncontextmenu
=
document.onmousedown
=
document.onkeydown
=
function
(){
return
true
;});
实际中发现如果不用alert语句套上,会导致浏览器重写当前窗口,于是就加上了。大家不妨试试,遇到不奏效的记得反馈下,我好研究是否有更完善的方案。