473,396 Members | 2,082 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,396 software developers and data experts.

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="javascript">
var IE = document.all?true:false;
if (!IE) document.captureEvents(event.MOUSEMOVE);
document.onmousemove = getMouseXY;

var x,y,tmpcords;

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

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

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

Best regards

Michael Christensen

Oct 24 '05 #1
3 5681
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>Javascript 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.javascript 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="javascript">
The language attribute is depreciated, type is required:

<script type="text/javascript">

var IE = document.all?true: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.captureEvents(event.MOUSEMOVE);
For some reading about how/when to use captureEvents:

<URL:http://www.quirksmode.org/js/events_order.html>
<URL:http://www.quirksmode.org/js/events_netscape4.html>

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

document.onmousemove = getMouseXY;
And add this one here...

if (document.captureEvents){
document.captureEvents(Event.MOUSEMOVE);
}

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.scrollLeft;
y = event.clientY + document.body.scrollTop;
} 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.scrollLeft;
y = event.clientY + document.body.scrollTop;
}

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


//Check if length is above 1200
if(document.all._clientEyeTextbox.value.length > 1200){
What is _clientEyeTextbox? 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._clientEyeTextbox;
if (1200 < textBox.value){
If _clientEyeTextBox 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._clientEyeTextbox.value = '';
This line will not be reached, but if it is was it should be:

textBox.value = '';
} else {
document.all._clientEyeTextbox.value =
document.all._clientEyeTextbox.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
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...
20
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...
3
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...
9
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,...
2
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...
5
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...
7
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. ...
2
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
0
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...
0
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,...

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.