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

firefox doesn't like the IE specific 'event' identifier and just quits running script

Hi
Firefox does not support the IE specific 'event' identifier and just quits
running the script.
..... even though the identifier only turns up in code marked for IE only ...

Does this seem reasonable?

The script is here:
http://www.lunds.us/private/coolclock.htm

This is the offending bit of script:
function Mouse(evnt){
ymouse =
(ns)?evnt.pageY+ClockFromMouseY-(window.pageYOffset):event.y+ClockFromMouseY;
xmouse = (ns)?evnt.pageX+ClockFromMouseX:event.x+ClockFromM ouseX;
}Is there a neat workaround?cheers, cw

Jul 23 '05 #1
5 3023
code_wrong wrote:
Hi
Firefox does not support the IE specific 'event' identifier and just quits
running the script.
.... even though the identifier only turns up in code marked for IE only ...
Your script may not doing what you think it is. If I'm running
Firefox, what value will the global variables "ie" and "ns" have
after this:

ns=(document.layers);
ie=(document.all);

If you guessed "undefined", you're right. So when you go to
execute your "code marked for IE only" (excuse trimming):

ymouse = (ns)?evnt.pageY+... : event.y+ClockFromMouseY;

What you are testing is not whether "ie" is true but whether
"ns" is true. Since ns is undefined, the test returns false and
your code tries to execute the stuff you've "marked for ie only".

Does this seem reasonable?

Depends on what your view of what is "reasonable". Using
detection of a single feature to infer the UA and hence
support for an entire environment is fatally flawed (as you've
discovered). That is probably unreasonable.
The script is here:
http://www.lunds.us/private/coolclock.htm

This is the offending bit of script:
Offensive? :-)
function Mouse(evnt){
ymouse =
(ns)?evnt.pageY+ClockFromMouseY-(window.pageYOffset):event.y+ClockFromMouseY;
xmouse = (ns)?evnt.pageX+ClockFromMouseX:event.x+ClockFromM ouseX;
}Is there a neat workaround?cheers, cw


Yes. Ditch browser detection completely. Use feature
detection. Detect and use W3C stuff first, if it fails, try
other (usually IE) stuff.

To fix your event issue,

function Mouse(evnt){
var e = evnt || window.event;

if (e.clientY)
ymouse = e.clientY+ClockFromMouseY;

} else if (e.y) {
ymouse = e.y+ClockFromMouseY;

} else if (e.pageY) {
ymouse = e.pageY+ClockFromMouseY-(window.pageYOffset);
}
}

Untested, but IIRC clientX and clientY are the W3C properties
you are looking for that are equivalent to x and y. They are
supported by IE 6 (and maybe earlier), testing for them first
will suit perhaps 99% of browsers (i.e. only old IE and old
Netscape will want something else).
--
Fred
Jul 23 '05 #2
Fred Oz wrote:
[...]

Ooops, left out xmouse. Only need to feature detect once (it's
very likely that if clientY is supported, so is clientX...):

function Mouse(evnt){
var e = evnt || window.event;

if (e.clientY)
ymouse = e.clientY+ClockFromMouseY; xmouse = e.clientX++ClockFromMouseX;
} else if (e.y) {
ymouse = e.y+ClockFromMouseY; xmouse = e.x+ClockFromMouseX;
} else if (e.pageY) {
ymouse = e.pageY+ClockFromMouseY-(window.pageYOffset); xmouse = e.pageX+ClockFromMouseX; }
}


--
Fred
Jul 23 '05 #3
Fred Oz wrote:
Fred Oz wrote:
[...]
Ooops, left out xmouse. Only need to feature detect once (it's
very likely that if clientY is supported, so is clientX...):
function Mouse(evnt){
var e = evnt || window.event;

if (e.clientY)
ymouse = e.clientY+ClockFromMouseY;

xmouse = e.clientX++ClockFromMouseX;

<snip>

It probably is valid to assume that an event object supporting clientX
will also support clientY. However, The style of testing you have
applied is problematic because the values being referred to are
primitive and so a type-converting test will produce results that depend
on the actual value. While an unsupported property will be undefined and
so type-convert to boolean false a numeric zero value (or an empty
string) will also type-convert to false. Where a property to be
tested/verified is an object or function, that will be undefined when
not implemented (and possibly null where supported but not present in
context), type-converting tests are probably optimum. Where a property
is expected to have a primitive value when implement a - typeof - test
is often necessary to produce reliable results.

Unfortunately, - typeof - testing is less efficient, but it can be
arranged that the testing does not need to be repeated each time a value
is read; the initial assumption still applies, if an event object
implements clientX the first time it is tested then the chances are good
that all (mouse related) event will also implement clientX, etc.

Richard.
Jul 23 '05 #4
code_wrong wrote:
Firefox does not support the IE specific 'event' identifier and just quits
running the script.
.... even though the identifier only turns up in code marked for IE only ...

Does this seem reasonable?

Frankly, yes it does. Consider this:-

You visit Russia. While there, you go to Lenin's Tomb and ask the guide
to explain how to see his personal effects. You ask in French. Do you
get upset because the guide only speaks Russian?

Javascript is a standard language and an interpreter using that standard
language recognises the standard terms of the language. If you throw in
terms that are not part of the languange, then it is no suprise when
they turn out to be meaningless.
Jul 23 '05 #5
Richard Cornford wrote:
Fred Oz wrote:
Fred Oz wrote: [...]
function Mouse(evnt){
var e = evnt || window.event;

if (e.clientY)
ymouse = e.clientY+ClockFromMouseY;
[...]
It probably is valid to assume that an event object supporting clientX
will also support clientY. However, The style of testing you have
applied is problematic because the values being referred to are
primitive and so a type-converting test will produce results that depend
on the actual value. While an unsupported property will be undefined and
so type-convert to boolean false a numeric zero value (or an empty
string) will also type-convert to false. Where a property to be
tested/verified is an object or function, that will be undefined when
not implemented (and possibly null where supported but not present in
context), type-converting tests are probably optimum. Where a property
is expected to have a primitive value when implement a - typeof - test
is often necessary to produce reliable results.

[...]

Thank you Richard ;-)

In case the OP missed it...

function Mouse(evnt){
var e = evnt || window.event;

if (typeof(e.clientY)){
ymouse = e.clientY+ClockFromMouseY;
...
}

If clientY is supported, typeof(e.clientY) will return "number"
or something other than "undefined" I guess and hence be
evaluated to true (or not false). I don't have a browser that
doesn't support it so untested .

--
Fred
Jul 23 '05 #6

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

Similar topics

3
by: coolsti | last post by:
Can someone help me enhance this code snippet which works only for IE so that it will also work for Firefox? I have been trying all sorts of things and have gotten to where I can capture the...
4
by: Stuart Perryman | last post by:
Hi, I have the following code which works just fine in IE6 but not in Firefox. It is an extract of several table rows each with an individual form. It is generated by php. <form...
3
by: niconedz | last post by:
Hi The following code works fine in IE but not Firefox. It's a little script that zooms an image and resizes the window to fit. Can anybody tell me what's wrong? Thanks Nico == btw.....
5
by: Martin Chen | last post by:
I have a frame set (as per MS FrontPage 2000). It has a contents and a main frame. The contents frame has a menu bar written with with javascript (in the context of a table). In IE6.1 everything...
10
by: Danny | last post by:
Hi all, I am having some odd problems with AJAX on Firefox (1.5). When I use GET as the request method everything works ok, but when I do a POST the remote function doesn't get the parameters I...
10
by: Paul Gorodyansky | last post by:
Hi, Ran into the problem today - in INPUT field Firefox executes clean-yp of the content if a user presses Esc, _before_ control goes to the code via onkeydown - and search showed that it's a...
3
by: Csaba Gabor | last post by:
Firefox's configuration settings (Prefs.js) can be accomplished via the interface at about:config. Q1. Is there any such setting that can be repeatedly altered via javascript (in a vanilla...
7
by: Coder | last post by:
Hi I have the following code in java script, it is not giving proper output in FIREFOX but running fine in IE... can anybody help me out to make this run in FIREFOX . <script...
1
by: littlealex | last post by:
IE6 not displaying text correctly - IE 7 & Firefox 3 are fine! Need some help with this as fairly new to CSS! In IE6 the text for the following page doesn't display properly - rather than being...
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: 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
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...
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
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.