我使用How to Disable Copy Paste (Browser)中的答案1在portal_javascript下注册了javascript 我遵循的步骤:1>将脚本复制到文件中
document.onkeydown = function(e) {
if (e.ctrlKey && e.keyCode === 65) {
// alert('not allowed');
return false;
}
if (e.ctrlKey && e.keyCode === 67) {
// alert('not allowed');
return false;
}
if (e.ctrlKey && e.keyCode === 86) {
// alert('not allowed');
return false;
}
};
document.oncontextmenu=new Function("return false")
步骤2)选择的portal_javascripts /在开发模式下添加了与此ID / url相同的脚本并保存。 3.在atreal.richfile.preview中,通过将onSelectStart和onSelectDrag上的鼠标按钮事件设置为False来自定义模板(atreal.richfile.preview.interfaces.ipreview-atreal.richfile.preview.viewlet)。通过删除预览窗口的右上方按钮并在此窗口中显示pdf以外的文件来更改代码。使用代码块:
<dl class="richfile portlet"
tal:condition="view/available"
tal:attributes="id view/plugin_id"
i18n:domain="atreal.richfile.preview">
<dt tal:attributes="id string:${view/plugin_id}Header" class="rfheader portletHeader">
<span class="portletTopLeft"></span>
<!--tal:block tal:replace="structure view/controls"-->
<span class="title" style="font-weight:bold"
i18n:translate="">
Preview
</span>
<span class="portletTopRight" ></span>
</dt>
<!--Your specific code here tal:condition="not:ispdf" -->
<dd>
<tal:block define="ispdf python:here.absolute_url().endswith('.pdf')">
<IFRAME src="http://www.xyz.com"
tal:condition="not:ispdf"
tal:attributes="src string:${here/absolute_url}/rfpreview"
width="100%" height="400" scrolling="auto" frameborder="1">
draggable="false" onselectstart="false"
</IFRAME>
</tal:block>
</dd>
</dl>
答案 0 :(得分:2)
尝试此操作以防止默认行为。
document.onkeydown = function(e) {
if (e.ctrlKey && e.keyCode === 65) {
alert('not allowed');
}
if (e.ctrlKey && e.keyCode === 67) {
alert('not allowed');
}
if (e.ctrlKey && e.keyCode === 86) {
alert('not allowed');
}
return false;
};
*DEMO *在结果窗口上进行测试,而不是在其他任何地方进行测试。
更新要禁用右键单击
<SCRIPT TYPE="text/javascript">
<!--
//Disable right click script
//visit http://www.rainbow.arch.scriptmania.com/scripts/
var message="Sorry, right-click has been disabled";
///////////////////////////////////
function clickIE() {if (document.all) {(message);return false;}}
function clickNS(e) {if
(document.layers||(document.getElementById&&!document.all)) {
if (e.which==2||e.which==3) {(message);return false;}}}
if (document.layers)
{document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;}
else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;}
document.oncontextmenu=new Function("return false")
// -->
</SCRIPT>