日期:2014-05-18  浏览次数:20407 次

[100分],有没有把禁止右键,禁止复制的js代码入Page基类中,以后不用每个页都要了的方法
我的公司的项目,有200页,每都写一遍
<body   leftmargin=0   topmargin=0   oncontextmenu= 'return   false '   ondragstart= 'return   false '   onselectstart   = 'return   false '   onselect= 'document.selection.empty() '   oncopy= 'document.selection.empty() '   onbeforecopy= 'return   false '   onmouseup= 'document.selection.empty() '>

太累了,也不复合程序员的标准方法,重用啊。所以,想求此方法。

谢谢大家了,好了,立即给分。

------解决方案--------------------
把类似于这样的脚本:

<script language=javascript>

document.onmouseup=function(){document.selection.empty()};
onbeforecopy=function(){return false;};

</script>

写在一个ascx里边,然后拖入每一个页面最上边或者最下边。

还有很多种,例如写一个Page子类在运行时输出脚本到页面,并且让所有页面inherits它,等等。你先想出 html/javascript方法,然后再考虑用哪一种asp.net实现它。
------解决方案--------------------
在页面基类中
protected void Page_Load(object sender, EventArgs e)
{
string myScript = @ "document.onmouseup=function(){document.selection.empty()};
onbeforecopy=function(){return false;};} ";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(),
"MyScript ", myScript, true);
}
------解决方案--------------------
您来帮助帮助我吧。
=======
1。
您太客气了。
很遗憾,我确实想不出来特别好的省时省力的方法,
用 Application_BeginRequest 你 boss 又不同意
用 PageBase 中 RegisterClient 不仅要修改所有页面的基类,而且还要在子类中的 Page_Load 中调用基类的 Page_Load
(当然如果你们页面用的 OnLoad(EventArgs) 方法原型就不需要了)

2。
因此,你应该考虑在自定义基类中的 PreRender 事件中执行 RegisterClientScriptBlock,并且通过
Find + Replace System.Web.UI.Page > > YourPageBase
VS 支持在整个项目中查找 替换
同样的,如果你的 .aspx.cs 重写了 PreRender 事件处理程序,记得显示调用基类的方法

Hope Helpful!
------解决方案--------------------
也可以尝试下我以前说的global方式,不符合标准,但是在ie和ff下都是正常工作的。你可以参考把这段代码写入global.asax
,ie和ff都测试过了.
protected void Application_BeginRequest(Object sender, EventArgs e)
{

Response.Write(@ " <script type= " "text/javascript " " language= " "javascript " "> document.onmouseup=function(){document.selection.empty();};document.onbeforecopy=function(){return false;};document.oncontextmenu=function(){return false;};document.ondragstart=function(){return false;};document.onselectstart=function(){return false;};document.onselect=function(){document.selection.empty();};document.oncopy=function(){document.selection.empty();};document.onbeforecopy=function(){return false;};document.onmouseup=function(){document.selection.empty();}; </script> ");
}

呵呵,标准化这个东西,但是也不用一味去追求,合用/符合用户群体才是最好的.
国内好多大站,ie下浏览正常,ff下就糊了.
我高一就开始研究w3c标准,到现在就只得出这个结论.