Outer Court

Tech - DOM/ DHTML - Prevention

Catching links

Do something else with all <a href> links on the page with the use of (non-standardized IE5) Behaviors.

The style:


  a { behavior: url(link.htc) }




The behavior ("link.htc") file:


<script language="JScript">

  attachEvent('onclick',clickLink);

  function clickLink()
  { 
    var strText = this.firstChild.data;
    var strUrl = this.attributes( "href" );

    // do something with these values now...

    event.returnValue = false;
  }

</script>




"this" in a HTC-file is a reference to the object that fired the event. If you use the click event and click on something deeply nested, remember "this" points to the element which holds the behavior, not to an element inside it!

The "event.returnValue = false" part is what actually prevents the linked page to be loaded.

Prevent selection

If you have a pseudo-dialog, you don't want it to be selectable (just as you can't for example copy the text on an "alert"). Here's the behavior-file:


  attachEvent( 'onselectstart', selstartDlg );

  function selstartDlg()
  {
    return false;
  }




You could make the dialog of class "dlg" and add the behavior to .dlg in the CSS.

Hiding the context menu

Found this snippet in a newsgroup:


  document.oncontextmenu = function () { return false };


Right Click sample

 
Basic
Goodies
Design
Tech
Email
Make a donation