Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Oct 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    oncontextmenu and internet explorer 7

    Hi
    A client wants to stop competitors from downloading images, ie right clicking and saving. I know it and you know this is a pointless task because you can get at the images without the menu, but they won't listen and they want it done. So to help them sleep at night i've cobbled together this...

    Code:
    window.onload = initAll;
    
    function initAll()
    {
    	var numImages = document.images.length;
    	
    	for(i=0; i < numImages; i++)
    	{
    		document.images[i].oncontextmenu = disableContextMenu;
    	}
    }
    
    function disableContextMenu()
    {
    	return false;
    }
    works fine in Firefox but fails to trigger in Internet Explorer 7 (haven't tried IE6) even though according to oncentextmenu msdn library it is possible.

    does anyone have any ideas, I would be perfectly happy if it only works in IE6 or IE7 because thats what the client uses and its for their piece of mind really.

    very grateful for any insight as to why its failing. cheers

    here is an example page with the javascript...
    http://www.gawpertron.com/test.html

  • #2
    New to the CF scene
    Join Date
    Oct 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I think i've figured it out. I went and had a little to eat and came back and re-read the msdn article and noticed "returnValue"

    so there you have it

    Code:
    window.onload = initAll;
    
    function initAll()
    {
    	var numImages = document.images.length;
    	
    	for(i=0; i < numImages; i++)
    	{
    		document.images[i].oncontextmenu = disableContextMenu;
    	}
    }
    
    function disableContextMenu(e)
    {
    	if(!e)
    	{
    		var e = window.event;
    		e.returnValue = false;
    	}
    		
    	return false;
    }
    this seems to work on on firefox 1 & 2, IE 6 & 7 (although on 6 it still shows those 4 little icons) and I don't expect it will work on Opera.

    So thats an afternoon and half an evening wasted,


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •