Stranger Stranger - 18 days ago 7
HTML Question

Prohibit Right Click Action On SWF files

I have a swf file and a html page which shows the swf file. I want to prohibit right click on swf file. I do not mean removing right click menu, I just want to prohibit the right click action. Then if you right click nothing will be happened.

Here is the html code:

<html>
<head><script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#swf-holder').bind("contextmenu", function(e) {
return false;
});
});
</script>


<title>Help Me</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<style type="text/css">html {overflow: hidden;}</style>
<style type="text/css">body { background-color: #07090e }#swf-holder { margin-top: 0px; width: 715px; position: center; top: 0px; left: 0%; margin-left: 0px; }</style>

</head>

<body>

<div id="swf-holder"><object id="content" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="715" height="580"><param name="movie" value="Main.swf" /><param name=quality value=best /><param name=bgcolor value=#07090e /><param name=allowScriptAccess value=always /><param name="wmode" value="opaque" /><object id="gecko" type="application/x-shockwave-flash" data="Main.swf" width="715" height="580" bgcolor=#4A4A4A wmode="opaque" quality="best"><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" border="0" alt="Get Adobe Flash player" /></a></object></object></div>

</body>
</html>


Any trick or idea for doing this?

Answer

Try putting this under the HEAD of your HTML page

<script language="text/javascript">
var message="Function Disabled!";
function clickIE4() {
    if (event.button==2) {
        alert(message); return false;
    }
}
function clickNS4(e) {
    if (document.layers||document.getElementById&&!document.all) {
        if (e.which==2||e.which==3){
            alert(message); return false;
        }
    }
}
if (document.layers) {
    document.captureEvents(Event.MOUSEDOWN);
    document.onmousedown=clickNS4;
} 
else if (document.all&&!document.getElementById) {
    document.onmousedown=clickIE4;
}
document.oncontextmenu=new Function("alert(message);return false")
</script>

(Edited code just for formatting reasons)

SOURCE: Hypergurl

There are some other methods on that page which may help you, but this seems like the easiest to implement.

Also, just so you are aware, if visitors to your site really want to get your content, there isn't any way to stop them from getting it other than not displaying it, using the right tools in the right browser, I (and you) can get an image off a site easily.

Comments