473,386 Members | 1,827 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

window.event good for IE but not Netscape/Firefox

RC
I am try to detect the mouse pointer by

var event = window.event;
var x = event.pageX;
var y = event.pageY;

This is working fine in IE, but in
Netscape/Firefox where event return undefined.

Can someone tel me how to detect mouse pointer
in Netscape/Firefox?

Thank Q very much in advance!
May 8 '06 #1
6 14373
Utilizo da seguinte maneira

var ns4 = (document.layers) ? true : false ;
var ie4 = (document.all) ? true : false;
function ColumnOnMouseMoveEvent (e){
var mouseX = 0;
mouseX=ie4? event.clientX : e.clientX;
var mouseY = 0;
mouseY=ie4? event.clientY : e.clientY;

}

May 8 '06 #2
ASM
RC a écrit :
I am try to detect the mouse pointer by

var event = window.event;
var x = event.pageX;
var y = event.pageY;

This is working fine in IE, but in
Netscape/Firefox where event return undefined.

function coords(e){
var x = e.pageX? e.pageX : 0;
var y = e.pageY? e.pageY : 0;
alert('x = '+x+'\ny = '+y);
}

<a href="#" onclick="coords(event)">event</a>

<html>
<script type="text/javascript">
function mousecoords(e){
var x = e.pageX? e.pageX : 0;
var y = e.pageY? e.pageY : 0;
document.getElementById('coord').innerHTML='x = '+x+' y = '+y;
}
</script>
<body onmousemove="mousecoords(event);">
<p id="coord"></p>
</html>
http://www.quirksmode.org/viewport/compatibility.html
--
Stephane Moriaux et son [moins] vieux Mac
May 8 '06 #3
ne*********@gmail.com said the following on 5/8/2006 3:37 PM:
Utilizo da seguinte maneira

var ns4 = (document.layers) ? true : false ;
var ie4 = (document.all) ? true : false;


And what about NS6/7/8, Mozilla, Firefox, Opera 5/6/7/8, or any other
browser that doesn't support document.all or document.layers or that
does support them but not e.clientX (in the case of document.all)?

Don't assume that one test implies other features. Test for the features
you want to use directly.

mouseX = (e.clientX)? e.clientX : event.clientX;
mouseY = (e.clientY)? e.clientY : event.clientY;

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
May 8 '06 #4
Randy, I agree to you

May 8 '06 #5
RC wrote:
I am try to detect the mouse pointer by

var event = window.event;
var x = event.pageX;
var y = event.pageY;

This is working fine in IE, but in
Netscape/Firefox where event return undefined.

Can someone tel me how to detect mouse pointer
in Netscape/Firefox?

Thank Q very much in advance!


Read about getting mouse co-ordinates (and events in general) here:

<URL:http://www.quirksmode.org/js/events_properties.html>
Based on the above reference, to get the cursor's co-ordinates from an
event:

function someFn(e)
{
var e = e : window.event;
var posx = 0;
var posy = 0;
if (e.pageX || e.pageY) {
posx = e.pageX;
posy = e.pageY;
} else if (e.clientX || e.clientY) {
posx = e.clientX + document.body.scrollLeft;
posy = e.clientY + document.body.scrollTop;
}
// posx and posy contain the mouse position relative to the document
// Do something with this information
}
And in the html:

<... onclick="someFn(event);" ...>
--
Rob
May 8 '06 #6
ne*********@gmail.com writes:
var ns4 = (document.layers) ? true : false ;
Detects true for Netscape 4 or OmniWeb (and isn't used here)
var ie4 = (document.all) ? true : false;
Detects true for IE or Opera or probably a few more.
function ColumnOnMouseMoveEvent (e){


A less fragile solution, that doesn't involve detecting the browser,
is to start the function with:
e = e || window.event;

If the event is passed as a parameter to the function (as Netscape and
W3C DOM Events compatible browsers do) this statement does nothing.

If not, it assumes that the event is available as a global variable
(as in IE).

To my knowledge, there is no browser supporting Javascript and events
that does neither.

var mouseX = e.clientX;
var mouseY = e.clientY;

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
May 10 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Brian | last post by:
Hi everyone, I'm writing a function (in javascript) that needs to do one thing if the page has not loaded, and another (different) thing if the page has already loaded. I'm looking for a way...
14
by: Frances Del Rio | last post by:
I'm trying to open a url in a new window while pg loads (but NOT in a pop-up..) I need to do sthg like // while pg is loading.. window.location ='page.html' // but I need this to open in a...
4
by: Andrew Poulos | last post by:
If I use this code to maximise a browser window: window.moveTo(0,0); window.resizeTo(screen.width,screen.height); it works but on Windows the user can have a taskbar visible and the browser...
3
by: jeff29_b | last post by:
I am having a strange problem on a web form. I have an image button with an OnClick event handler. When I click the image the event isn't being called in the code behind when browsing in firefox....
22
by: stephen | last post by:
I have created an order form that users javascript to create a new html document when the customers clicks the "print page" button. Once the new document has been created it then prints the...
8
by: David Gravereaux | last post by:
Hi, I'm using chunked transfer-coding to send an "unending" page, but IE _NEVER_ fires onresize events until the page is finished. Unfortunately, the page never is "finished". How do I handle...
26
by: yb | last post by:
Hi, Is there a standard for the global 'window' object in browsers? For example, it supports methods such as setInterval and clearInterval, and several others. I know that w3c standardized...
18
by: len.hartley | last post by:
Hi, I am trying to pop-up a window when the user clicks on an image. The problem is that when the user clicks on the image and the window pops up OK, but the window underneath also proceeds to...
10
by: Andrew Neiderer | last post by:
I think I am asking the right newsgroup. If not maybe someone could tell me where to ask this "beginner" question. I want to click on an image (.jpg) that launches a Microsoft window (cmd.exe...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.