spacer
Yehuda Shiran January 15, 2001
Retrieving Event Location
Tips: January 2001

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
OpenOffice 3.2 Lands Amid Critical Changes
Red Hat, IBM Firmly in KVM Virtualization Camp
Red Hat Talks Up Open Source Cloud Plans

The e object holds a lot of information about the Netscape 6 event. The pageX and pageY properties, for example, reveals the location of the event, relative to the document's top left corner, in pixels. The following statement prints the pageX and pageY property values to the status window:

window.status = "X = " + e.pageX + "   Y = " + e.pageY;

The status window is shown on the bottom left corner of Netscape 6 window. Notice that you have to pass the e object as a parameter to those functions which reference it. In the following example, we pass the e object as a parameter to colorItTan():

<DIV ID="demoDiv" STYLE="position:relative; left:100px; top:20px; width:220px; 
height:25px; color:blue; background-color:yellow;">Click me with the left button! 
</DIV>
<SCRIPT LANGUAGE="JavaScript">
<!--
var demoObj;

function init() {
  demoObj = document.getElementById("demoDiv");
  demoObj.addEventListener("click", colorItTan, false);
}

function colorItTan(e) {
  demoObj.style.backgroundColor = "tan";
  window.status = "X = " + e.pageX + "   Y = " + e.pageY;
}

onload = init; 
// -->
</SCRIPT>

Get on Netscape 6 browser and play with this demo. Click the left button and observe the coordinates in the status window.


People who read this tip also read these tips:

Look for similar tips by subject:


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

webref The latest from WebReference.com Browse >
Search Engine Optimization: Selecting and Embedding Keywords · Are Google's Language Translation Web Services Ready for Prime Time? · Installing and Using Meeplace, the Business Review CMS
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Workers Say Telework Is More Productive, Bosses Not So Sure · Kingston Debuts Power-Saving Memory Upgrades · Social Networking is King: Facebook Edges Google