使用JS禁止页面打印,右击保存图片

使得当前页面上的图片不能够右击保存,打印当前页面时,图片为空

<script language="JavaScript1.2">
//测试剪切板为空
function testclip(){ try { if(clipboardData.getData("Text")||clipboardData.getData("HTML")||clipboardData.getData("URL")) { null; } } catch(e){ clipboardData.setData("Text","") } setTimeout("testclip()",500) } testclip();
//禁止右键
var clickmessage="Right click disabled on images!" function disableclick(e) { if (document.all) { if (event.button==2||event.button==3) { if (event.srcElement.tagName=="IMG"){ alert(clickmessage); return false; } } } if (document.layers) { if (e.which == 3) { alert(clickmessage); return false; } } } function associateimages(){ for(i=0;i<document.images.length;i++) document.images[i].onmousedown=disableclick; } if (document.all) document.onmousedown=disableclick else if (document.layers) associateimages()

</script>

<style>

//设置打印的时候页面为空 @media Print { BODY { DISPLAY: none } } </style>

 

posted @ 2015-03-25 13:44  batter152  阅读(1150)  评论(0编辑  收藏  举报