473,698 Members | 2,690 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 14388
Utilizo da seguinte maneira

var ns4 = (document.layer s) ? true : false ;
var ie4 = (document.all) ? true : false;
function ColumnOnMouseMo veEvent (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.getEle mentById('coord ').innerHTML='x = '+x+' y = '+y;
}
</script>
<body onmousemove="mo usecoords(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*********@gma il.com said the following on 5/8/2006 3:37 PM:
Utilizo da seguinte maneira

var ns4 = (document.layer s) ? 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.javas cript 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_properti es.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.s crollLeft;
posy = e.clientY + document.body.s crollTop;
}
// 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*********@gma il.com writes:
var ns4 = (document.layer s) ? 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 ColumnOnMouseMo veEvent (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/rasterTriangleD OM.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
4569
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 to tell if the window.onload event has already fired. I cannot edit the onload event handler itself, and my function can only exist in an external js file, sourced from the document's head section. Any ideas?
14
37152
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 new blank window.. // (NOT in a pop-up, a regular new window..) can you do this?? thank you..
4
6330
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 window goes behind it. Is there a way to know where the taskbar is?
3
3152
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. I get the postback but I never have the event called. It works fine in i.e.
22
130261
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 document and closes it with the following code: <body onload="window.print(); window.close();"> This works correctly (or at least the way I expect it to work under MS Internet Explorer, but it cuases Netscape to "crash"
8
7856
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 this?
26
5680
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 several parts of the DOM, but this does not include the window object. Thank you
18
3335
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 the image. The desired behavior is that when the pop-up is invoked, I want the underlying window to stay put. I don't have this problem when I run the code on my local computer but I do have it when I run the code on geocities.
10
3632
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 or command.com) which executes some .exe, e.g googleearth.exe. I know this is simple for most of you but I am just starting XHTML. I think it begins with <html> <body>
0
9170
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8901
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8871
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7739
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5862
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4371
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2336
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.