Disabling the right click function in the Popped up window!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kkganakga
    New Member
    • Mar 2007
    • 1

    Disabling the right click function in the Popped up window!

    Hi,

    I used a short code to pop up a thumbnail in a new window for a gallery view. The problem is I would like to disable the right click function on the popped up / new window. How can I do this?

    This is the code i used to pop up the window:

    <a href="#"><img src="sml/17.jpg" alt="Garden!" style="" onclick="javasc ript:window.ope n('lrg/17.jpg','new',' width=850,heigh t=650,resizeabl e=no,directorie s=no,toolbar=no ,scrollbars=yes ,left=12,top=0' );" width="72" height="71" border="0" /></a>

    Thank you!
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Welcome to TSDN.

    I assume you know how to disable right-click, but need to access the new window. Put your code into a function and call that in the onclick of the link. When calling window.open, keep a ref. to the window:
    Code:
    var newWin = window.open(...);
    then you can newWin to access the new window.

    There are lots of scripts that let you disable right-click. Find them using a simple Google search. However, anyone determined enough will easily be able to bypass this 'security' measure.

    Comment

    • Gyanchand
      New Member
      • Jul 2007
      • 35

      #3
      hey try this

      'Create a new page where the image will be placed. And popup this as the new window. Add this code in your script section of the popup page

      [CODE=javascript]function disable_right_c lick(e)
      {
      var browser = navigator.appNa me.substring ( 0, 9 );
      var event_number = 0;
      if (browser=="Micr osoft")
      event_number = event.button;
      else if (browser=="Nets cape")
      event_number = e.which;

      if ( event_number==2 || event_number==3 )
      {
      alert ("© ABC Co.Ltd. All rights reserved");
      return (false);
      }

      return (true);
      }

      function check_mousekey ()
      {
      var mouse_key = 93;
      var keycode = event.keyCode;

      if ( keycode == mouse_key )
      alert ( "© ABC Co.Ltd. All rights reserved" );
      }

      function trap_page_mouse _key_events ()
      {
      var browser = navigator.appNa me.substring ( 00, 9 );

      document.onmous edown = disable_right_c lick;

      if ( browser == "Microsoft" )
      document.onkeyd own = check_mousekey;
      else if ( browser == "Netscape" )
      document.captur eEvents( Event.MOUSEDOWN );
      }

      window.onload = trap_page_mouse _key_events;[/CODE]

      Comment

      Working...