473,574 Members | 2,474 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Events in Mozilla and firefox?

The following works fine in IE -> what am I missing to make it work in
Firefox - an example would be great?

I can't figure it out :-)
------------------------------------------------
<body>

<script language="javas cript">
var IE = document.all?tr ue:false;
if (!IE) document.captur eEvents(event.M OUSEMOVE);
document.onmous emove = getMouseXY;

var x,y,tmpcords;

function getMouseXY(e) {
if(IE){
x = event.clientX + document.body.s crollLeft;
y = event.clientY + document.body.s crollTop;
} else {
x = e.pageX;
y = e.pageY;
}

//Check if length is above 1200
if(document.all ._clientEyeText box.value.lengt h > 1200){
return calc();
document.all._c lientEyeTextbox .value = '';
} else {
document.all._c lientEyeTextbox .value =
document.all._c lientEyeTextbox .value + x + ',' + y + ',';
//document.all.a. value = document.all.a. value + x + ',' + y + ',';
}
}
</script>

</body>
------------------------------------------------

Best regards

Michael Christensen

Oct 24 '05 #1
3 5689
Michael Christensen said the following on 10/24/2005 2:08 PM:
The following works fine in IE -> what am I missing to make it work in
Firefox - an example would be great?

I can't figure it out :-)


Try Tools>Javascrip t Console
Stop assuming that the existence of document.all means you are dealing
with IE - it doesn't.
Stop thinking you need to know what browser you are dealing with - you
don't.
Start feature detecting.
--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Oct 24 '05 #2
Michael Christensen wrote:
The following works fine in IE -> what am I missing to make it work in
Firefox - an example would be great?

I can't figure it out :-)
------------------------------------------------
<body>

<script language="javas cript">
The language attribute is depreciated, type is required:

<script type="text/javascript">

var IE = document.all?tr ue:false;
When posting code, indent using 2 or 4 spaces, not tabs. It helps to
stop wrapping which nearly always introduces errors. Manually wrap code
at about 70 characters (same reason).

As Randy said, browser detection based on whether or not certain
functions are supported is flawed. Simply don't do it.

if (!IE) document.captur eEvents(event.M OUSEMOVE);
For some reading about how/when to use captureEvents:

<URL:http://www.quirksmode. org/js/events_order.ht ml>
<URL:http://www.quirksmode. org/js/events_netscape 4.html>

Remove the -- if (!IE)... -- line...

document.onmous emove = getMouseXY;
And add this one here...

if (document.captu reEvents){
document.captur eEvents(Event.M OUSEMOVE);
}

var x,y,tmpcords;
It's probable that these globals aren't needed. If the issue is
returning multiple values from a function, you can do that by putting
them into an array and return that.


function getMouseXY(e) {
if(IE){
x = event.clientX + document.body.s crollLeft;
y = event.clientY + document.body.s crollTop;
} else {
x = e.pageX;
y = e.pageY;
}
Once you remove browser sniffing, the above becomes:

function getMouseXY(e)
{
var e = e || window.event;
if (e.pageX || e.pageY){
x = e.pageX;
y = e.pageY;
} else if (e.clientX || e.clientY) {
x = event.clientX + document.body.s crollLeft;
y = event.clientY + document.body.s crollTop;
}

<URL:http://www.quirksmode. org/js/events_properti es.html>


//Check if length is above 1200
if(document.all ._clientEyeText box.value.lengt h > 1200){
What is _clientEyeTextb ox? If it's the name of a form control, then the
best way to access it is to get a reference then use that ('formName' is
the name of the form):

var textBox = document.forms. formName._clien tEyeTextbox;
if (1200 < textBox.value){
If _clientEyeTextB ox is the id of the control, then it's invalid since
id attributes must start with a letter (it's OK for a name to start with
an underscore, but certain valid name characters will cause problems in
places depending on how you access the control). Read the HTML spec on
name and id attributes.

return calc();
The function will end here if the if statement returned true.
document.all._c lientEyeTextbox .value = '';
This line will not be reached, but if it is was it should be:

textBox.value = '';
} else {
document.all._c lientEyeTextbox .value =
document.all._c lientEyeTextbox .value + x + ',' + y + ',';
textBox.value += x + ',' + y + ',';

Since you seem to be storing x and y in the text box, they need not be
global variables. And if the text box is a device for passing the
values to some other function, you could use:

return [x, y];

to return the values in an array - but my assumption may be a wrong.

//document.all.a. value = document.all.a. value + x + ',' + y + ',';
}
}
</script>

</body>


All the above is untested - if you provide some working code with
associated HTML (minimal working example) then better help can be provided.

--
Rob
Oct 24 '05 #3
VK
> Events in Mozilla and firefox?

A bit offtopic but important to mention:
The question sounds similar to: "Difference between mammals and cows".
Any modern graphical browser is Mozilla meaning it has "Mozilla" in its
USER_AGENT string.

Oct 25 '05 #4

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

Similar topics

6
3301
by: Thomas | last post by:
Hi, I'm having a problem with the dynamically created inputfields in Internet Explorer. The situation is the following: - I have a dynamically created table with a textbox in each Cell. - It is possible to Add and Delete rows - Some cells have special attributes (readonly and events) Here's a snippet of the code:
20
12874
by: David | last post by:
I have a one-line script to add an onunload event handler to the body of the document. The script is as follows: document.getElementsByTagName("BODY").onunload=function s() {alert("s")} Now obviously, I put the alert("s") part in for debugging purposes, just to make sure the error wasn't in any code I was going to be running. This line...
3
7890
by: Praveen | last post by:
In IE a table element will receive focus when you either tab into it or when you click anywhere within the table. Mainly it fires the onfocus event. This doesn't happen in Mozilla (Firefox and Netscape). Is there any setting or anyother way to force the table element to fire the onfocus and onblur events? Thanks
9
1654
by: Lachlan Hunt | last post by:
Hi, I've written some javascript to implement DOM 2 Events in IE (addEventListener, removeEventListener, etc) and I would like to know which browsers it works in. I've tested it in Firefox 1.0.6, Deer Park Alpha 2, Opera 8.02 and IE6 and IE7 Beta 1, all on WinXP SP2. Could some of you please take a look at the test pages in any browser...
2
3212
by: Arnaud Diederen | last post by:
Hello, I cannot succeed in getting any key event on a div that's been set invisible by the style's MozOpacity property under firefox. I'm using this method so that I can capture the mouse events. Unfortunately, it appears to do so only with mouse events, not key events. Is there a better solution than the following? :
5
4370
by: Richard Maher | last post by:
Hi, Here I mean "User" in the Programmer or Javascript sense. I merely wish to programmatically trigger an Event. It would be absolutely fantastic if there was a (Form level?) ONUSEREVENT() and a setEvent() function but, in the absence of this, is it not possible to use DOM to change an object's properties resulting in a state-change event?...
7
2321
by: mavigozler | last post by:
IE7 does not appear to set an event on contained text inside SPAN elements whose 'onclick', 'onmouseover', and 'onmouseout' events, defying the HTML recommendation. Firefox appears to conform. Is that so?
2
4216
by: Lazarus | last post by:
Hi, I have a canvas that reacts to mousedown and mousemove. Once I click the canvas I want to track the cursor wherever it goes, including outside the browser. Setting window.onmousemove only gives events inside the browser of course. I tried window.captureEvents which works on Safari but FireFox says it's deprecated. Mozilla's docs say to use...
0
7710
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8040
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. ...
0
8225
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8092
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...
1
5610
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3738
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...
0
3745
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2230
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1332
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.