最近剛好有一個這樣的需求,這個需求不是在防止別人偷看原始碼..
要防止IE按右鍵與選取最簡單的方法就是在Body加入下列語法
1 |
<body onDragStart="return false" oncontextmenu="return false" onSelectStart="return false" > |
也可以用asp.net程式動態加入這些語法
asp.net(c#)
Default.aspx
01 |
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> |
07 |
<body id="body" runat="server"> |
08 |
<form id="form1" runat="server"> |
Default.aspx.cs
03 |
public partial class _Default : System.Web.UI.Page |
05 |
protected void Page_Load(object sender, EventArgs e) |
10 |
this.body.Attributes.Add("oncontextmenu", "return false"); |
13 |
this.body.Attributes.Add("onSelectStart", "return false"); |
15 |
this.body.Attributes.Add("onDragStart", "return false"); |
執行結果:

推到 Twitter!