Coding Tips (JavaScript/CSS/VBA/Win32)

Useful code snippets, tips and some Windows applications
Use ProxyChanger 2.2
to change IE proxy settings

More Javascript Tips

Disable Right Click On Images Only

 function disable_right_click(e)
  {
      var browser = navigator.appName.substring ( 0, 9 );
      var event_number = 0;

      if (browser=="Microsoft")
          event_number = event.button;
      else if (browser=="Netscape")
          event_number = e.which;

      if ( event_number==2 || event_number==3 )
          {
          alert ("Right Mouse Button Is Disabled");
          return (false);
          }

      return (true);
  }

  function trap_images_mouse_events ()
  {
      if ( document.images )
          {
          for (var pic=0; pic<document.images.length; pic++)
              document.images[pic].onmousedown = disable_right_click;
          }
  }

  window.onload = trap_images_mouse_events;

Check if a Variable Exists

This problem often occurs if code tries to use a variable that has not been defined before. Then you get 'a variable is not defined' error.

One of the solutions is to use window.variableName.

The usage is simple: if(window.variableName)...

Passing Arguments to The Onload Event Function

The onload event handler can be used to attach a function that will be executed when the page has finished loading. A reference to the function is passed as follows:

window.onload = init;

There is a problem with this approach that no arguments can be passed to the function using this syntax. The solution is to use an anonymous function:

window.onload = function () {init("arg1");};





Links

An extensive JavaScript Form FAQ Knowledge Base from It.org