Script that counts not clicks; RIGHT clicks!

Discussion in 'Programming' started by webtracker, Dec 9, 2006.

  1. #1
    Anyone know of a script (PHP or JAVASCRIPT) that would increment a counter when a user RIGHT CLICKS?

    I have a TEXTAREA field on a page of mine where I´ll be placing some code and want to know everytime someone right clicks the code (as if they were going to copy it).


    Thanks.
     
    webtracker, Dec 9, 2006 IP
  2. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #2
    example.html or .php doesn't matter

    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    <script type="text/javascript">
    <!--
    function processAjax()
    {
    	xmlHttp=GetXmlHttpObject() // Create xmlHTTP Object
    	var url="AjaxProcess.php" // Begin to build the url to the proccessing script
    	url=url+"?process=count"
    	url=url+"&sid="+Math.random()
    	xmlHttp.onreadystatechange=StateChanged // Discover state changes
    	xmlHttp.open("GET",url,true) // Open object at the url specified
    	xmlHttp.send(null) // Send the AJAX request
    }
    /**
    * Detecting if a state has changed
    **/
    function StateChanged() 
    { 
    	//document.write(ElementId);
    	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    	{ 
    	document.getElementById('ex').innerHTML=xmlHttp.responseText 
    	}
    } 
    /**
    * This function calls an xmlHTTP object for use to do whatever....
    **/
    function GetXmlHttpObject()
    { 
    var objXMLHttp=null
    	if (window.XMLHttpRequest)
    	{
    		objXMLHttp=new XMLHttpRequest()
    	}
    	else if (window.ActiveXObject)
    	{
    	objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
    	}
    return objXMLHttp
    } 
    function SneakySneaky(e) 
    {
    	if (document.all) 
    	{
    		if (event.button == 2) 
    		{
    			processAjax();
    		}
    	}
    	if (document.layers) 
    	{
    		if (e.which == 3) 
    		{
    			processAjax();
    		}
    	}
    }
    if (document.layers) 
    {
    	document.captureEvents(Event.MOUSEDOWN);
    }
    //-->
    </script>
    </head>
    
    <body>
    <span id="ex" onmousedown="javascript: SneakySneaky();">
    What you doing, bored are we ??<br />
    Why not click about on the page, go on click anywhere you want<br />
    As much as you like, <strong>BUT</strong> don't click on me here<br />
    You'll make me angry, you have neem warmed<br />
    </span>
    </body>
    </html>
    
    Code (markup):
    AjaxProcess.php

    
    <?
    if($_GET['process'] == "count")
    {
    	$responseText = "<strong>ALERT :</strong> You made me angry, I told this  was protected content and now you've given me your ip address" . $_SERVER['REMOTE_ADDR'] . " and that's NOT clever !!";
    }
    
    echo $responseText;
    ?> 
    
    PHP:
    He shoots.....he scores .....

    works in Internet explorer, not firefox, but that's coz I'm not really putting effort in, if you don't know how to make the ajaxprocess write files or whatever, then post again

    if someone way of detecting right clicks in firefox then speak up......
     
    krakjoe, Dec 9, 2006 IP