473,383 Members | 1,868 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,383 software developers and data experts.

Detect Firefox 1.5 from previous Firefox's

VK
if ((window)&&(window.netscape)&&(window.netscape.sec urity)) {
// OK, this is Gecko/Firefox or someone mimicing it so well
// that there is no way to catch it on the act.
}

But I need Firefox *1.5 or higher* or another (but sure) way to know
that this browser has native SVG support. Here I'm stock.

It seems there is window.navigator.productSub and on my Firefox 1.5
it's 20051111

But I'm not sure: this "build version" is going up guaranteed or it's
random like CLASSID? Also is the same Firefox release has the same
build for all platforms or not? mozilla.org seems silent.

Jan 7 '06 #1
9 3283
VK wrote:
But I need Firefox *1.5 or higher* or another (but sure) way to know
that this browser has native SVG support. Here I'm stock.


Try this (test for the new XML object, the SVG related MIME type and the
absence of a SVG plugin):

if(window.XML && navigator.mimeTypes &&
navigator.mimeTypes["image/svg+xml"] &&
!navigator.mimeTypes["image/svg+xml"].enabledPlugin)

I use this method in my examples like this one:
<http://svglbc.datenverdrahten.de/?code=Mozilla-DOM-Test_1&znr=on>

cu, Thomas
--
SVG - Learning By Coding
<http://svglbc.datenverdrahten.de/>
Jan 7 '06 #2


VK wrote:
But I need Firefox *1.5 or higher* or another (but sure) way to know
that this browser has native SVG support.


Native SVG can be disabled by setting the preference
svg.enabled
to false. If it is enabled Firefox 1.5 respectively Gecko 1.8 returns
true for
document.implementation.hasFeature("org.w3c.dom.sv g", "1.0")
otherwise false.
See also
<https://bugzilla.mozilla.org/attachment.cgi?id=190953>
which is a test case for
<https://bugzilla.mozilla.org/show_bug.cgi?id=302640>

Note that it is debatable whether Mozilla's incomplete SVG DOM
implementation should return true for that feature org.w3c.dom.svg but
they had that already enabled in Gecko 1.8, only permanent without
checking whether SVG is really enabled, now that the bug is fixed they
at least only return true if SVG is enabled.

There are other ways to check, if you create e.g.

var svgElement = document.createElementNS('http://www.w3.org/2000/svg',
'svg');

then only with native SVG supported and enabled that element is
implementing SVG DOM specific stuff, otherwise it will only be an
element object implementing core DOM stuff. That way you can check e.g.

var svgElement = document.createElementNS('http://www.w3.org/2000/svg',
'svg');
if (typeof svgElement.width != 'undefined') {
// native SVG (DOM) support
}

Both described checks are feature checks and no "Firefox 1.5" checks,
the latter test for instance will also yield true in Opera 9 preview
with its native SVG (DOM) support.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jan 7 '06 #3

Thomas Meinike wrote:
I use this method in my examples like this one:
<http://svglbc.datenverdrahten.de/?code=Mozilla-DOM-Test_1&znr=on>


It would be safer to use importNode instead of simply moving nodes, e.g.
you have

xmlobject=req.responseXML;
svgobject=xmlobject.documentElement.getElementsByT agName("g").item(0);
document.documentElement.appendChild(svgobject);

which works in Mozilla but would fail with Opera so doing

xmlobject=req.responseXML;
svgobject=document.importNode(xmlobject.documentEl ement.getElementsByTagName("g").item(0),
true);
document.documentElement.appendChild(svgobject);

instead is safer.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jan 7 '06 #4
VK

Martin Honnen wrote:
VK wrote:
But I need Firefox *1.5 or higher* or another (but sure) way to know
that this browser has native SVG support.


Native SVG can be disabled by setting the preference
svg.enabled
to false. If it is enabled Firefox 1.5 respectively Gecko 1.8 returns
true for
document.implementation.hasFeature("org.w3c.dom.sv g", "1.0")
otherwise false.
See also
<https://bugzilla.mozilla.org/attachment.cgi?id=190953>
which is a test case for
<https://bugzilla.mozilla.org/show_bug.cgi?id=302640>

Note that it is debatable whether Mozilla's incomplete SVG DOM
implementation should return true for that feature org.w3c.dom.svg but
they had that already enabled in Gecko 1.8, only permanent without
checking whether SVG is really enabled, now that the bug is fixed they
at least only return true if SVG is enabled.

There are other ways to check, if you create e.g.

var svgElement = document.createElementNS('http://www.w3.org/2000/svg',
'svg');

then only with native SVG supported and enabled that element is
implementing SVG DOM specific stuff, otherwise it will only be an
element object implementing core DOM stuff. That way you can check e.g.

var svgElement = document.createElementNS('http://www.w3.org/2000/svg',
'svg');
if (typeof svgElement.width != 'undefined') {
// native SVG (DOM) support
}

Both described checks are feature checks and no "Firefox 1.5" checks,
the latter test for instance will also yield true in Opera 9 preview
with its native SVG (DOM) support.

--

Martin Honnen
http://JavaScript.FAQTs.com/


Absolutely great, thanks to you both.

Hacking Mozilla was not so difficult after I've got (grace to Martin
Honnen) the meaning of createElementNS. This also covered the last
stable Camino (theoretically - as I don't have Mac OS handy).

Opera was more stubbering. btw Opera sucks (if someone is not aware of
it yet) - both in style scripting support and majorly in transparency.
But their SVG Tiny seems pretty stable and does what documented.

Easier of all was with Microsoft VML as it was originally (since 1998)
made for in-HTML use and is fully implemented in all releases.

Also I'd like to "copyright" by spelling it publically :-)) the term
SVL - Superimposed Vector Language - which is an interface atop Opera
SVG Tiny, Gecko SGV GodKnowsWhat and Microsoft VML.

Here's the current hack for *Opera* I'm working with - the code is a
total crazy mess as I'm working on the run and I have 2 days left for
the project. May be an inspiration to someone (doubt it *very* much) or
an advise. Transparency is a killer in Opera...

<html>
<head>
<title>Opera</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">

<link id="style1" rel="stylesheet" href="_opera.css">

<script type="text/javascript">

function SVL_OperaCanvas(w,h,p,x,y) {
var ww = parseInt(w,10) || 250;
var hh = parseInt(h,10) || 200;
var pp = p || 'static';
var xx = parseInt(x,10) || 0;
var yy = parseInt(y,10) || 0;
var canvas = SVL_SVGOperaFactory('svg');
SVL_SVGOperaSetAttribute(canvas,'baseProfile','tin y');
SVL_SVGOperaSetAttribute(canvas,'version','1.1');
SVL_SVGOperaSetAttribute(canvas,'width',ww);
SVL_SVGOperaSetAttribute(canvas,'height',hh);
SVL_SVGOperaSetAttribute(canvas,'viewBox',('0 0 '+ww+' '+hh));
SVL_SVGOperaSetAttribute(canvas,'preserveAspectRat io','none');
var rect = SVL_SVGOperaFactory('rect');
SVL_SVGOperaSetAttribute(rect,'x',0);
SVL_SVGOperaSetAttribute(rect,'y',0);
SVL_SVGOperaSetAttribute(rect,'width',ww);
SVL_SVGOperaSetAttribute(rect,'height',hh);
SVL_SVGOperaSetAttribute(rect,'fill','#3067C0');
SVL_SVGOperaSetAttribute(rect,'fill-opacity','0.6');
SVL_SVGOperaSetAttribute(rect,'stroke','#0000FF');
SVL_SVGOperaSetAttribute(rect,'stroke-opacity','0.6');
SVL_SVGOperaSetAttribute(rect,'stroke-width','1px');
canvas.appendChild(rect);
return canvas;
}

function SVL_SVGOperaFactory(tag) {
return document.createElementNS('http://www.w3.org/2000/svg',tag);
}

function SVL_SVGOperaSetAttribute(obj,attr,val) {
obj.setAttributeNS('http://www.w3.org/2000/svg',attr,val);
}

function test() {
var obj = SVL_OperaCanvas();
document.getElementById('Layer1').appendChild(obj) ;
}
</script>
</head>

<body onload="test()">
<div id="Layer1" style="position:absolute; width:250px; height:200px;
z-index:1; left: 10px; top: 10px"></div>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
enim ad minim veniam, quis nostrud exercitation ullamco laboris
nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
reprehenderit in voluptate velit esse cillum dolore eu
fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident,
sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>

</body>
</html>

Jan 7 '06 #5

VK wrote:
var canvas = SVL_SVGOperaFactory('svg');
SVL_SVGOperaSetAttribute(canvas,'baseProfile','tin y');
SVL_SVGOperaSetAttribute(canvas,'version','1.1');
SVL_SVGOperaSetAttribute(canvas,'width',ww);
SVL_SVGOperaSetAttribute(canvas,'height',hh); function SVL_SVGOperaFactory(tag) {
return document.createElementNS('http://www.w3.org/2000/svg',tag);
}

function SVL_SVGOperaSetAttribute(obj,attr,val) {
obj.setAttributeNS('http://www.w3.org/2000/svg',attr,val);


Note that the attributes (like width, height) on SVG elements are in no
namespace so trying to set those attributes in the SVG namespace
http://www.w3.org/2000/svg does not make sense, you either want
obj.setAttributeNS(null,attr,val)
or use setAttribute instead.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jan 7 '06 #6
Martin Honnen wrote:
It would be safer to use importNode instead of simply moving nodes, ...


Thanks for the hint.

cu, Thomas
--
SVG - Learning By Coding
<http://svglbc.datenverdrahten.de/>
Jan 8 '06 #7
VK

Martin Honnen wrote:
Note that the attributes (like width, height) on SVG elements are in no
namespace so trying to set those attributes in the SVG namespace
http://www.w3.org/2000/svg does not make sense, you either want
obj.setAttributeNS(null,attr,val)
or use setAttribute instead.


I think it is discutable because in the given case I don't manipulate
width or height of HTML holder (like EMBED, OBJECT or IFRAME) but
directly SVG element itself which is not in HTML namespace. Nmaely
we're emulating the needed namespace environment for the svg object to
have it happy (as it was in <xml> or <svg> document), so anything
should come from that emulated environment (?)

<http://www.w3.org/TR/SVG/struct.html#SVGElement>
width = "<length>"
For outermost 'svg' elements, the intrinsic width of the SVG
document fragment

That's too much of abstract theory for my humble mind to get it right
away. Opera seems to eat it as it is just fine. But I promise to think
more over it :-)

Jan 9 '06 #8


VK wrote:
Martin Honnen wrote:
Note that the attributes (like width, height) on SVG elements are in no
namespace so trying to set those attributes in the SVG namespace
http://www.w3.org/2000/svg does not make sense, you either want
obj.setAttributeNS(null,attr,val)
or use setAttribute instead.

I think it is discutable because in the given case I don't manipulate
width or height of HTML holder (like EMBED, OBJECT or IFRAME) but
directly SVG element itself which is not in HTML namespace. Nmaely
we're emulating the needed namespace environment for the svg object to
have it happy (as it was in <xml> or <svg> document), so anything
should come from that emulated environment (?)


There is no HTML namespace or any namespaces in HTML as defined by the
W3C. And attributes in XML with namespaces are in no namespace unless
they have a qualified name with a prefix bound to a namespace URI. If
you have example XML/SVG markup alike
<svg xmlns="http://www.w3.org/2000/svg"
width="200" height="200"></svg>
then the svg element is in the SVG namespace with namespace URI
http://www.w3.org/2000/svg but those attributes (width, height) are in
no namespace. The SVG specification defines a few attributes like
xlink:href (with the xlink prefix bound to the namespace URI
http://www.w3.org/1999/xlink) which are in a namespace but most of the
attributes on SVG elements are in no namespace.
And if you want to create such attributes in no namespace with the W3C
DOM Level 2 Core setAttributeNS method then you need to pass null for
the namespace URI to that method:
<http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-745549614>
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jan 9 '06 #9
VK

Martin Honnen wrote:
There is no HTML namespace or any namespaces in HTML as defined by the
W3C. And attributes in XML with namespaces are in no namespace unless
they have a qualified name with a prefix bound to a namespace URI. If
you have example XML/SVG markup alike
<svg xmlns="http://www.w3.org/2000/svg"
width="200" height="200"></svg>
then the svg element is in the SVG namespace with namespace URI
http://www.w3.org/2000/svg but those attributes (width, height) are in
no namespace. The SVG specification defines a few attributes like
xlink:href (with the xlink prefix bound to the namespace URI
http://www.w3.org/1999/xlink) which are in a namespace but most of the
attributes on SVG elements are in no namespace.
And if you want to create such attributes in no namespace with the W3C
DOM Level 2 Core setAttributeNS method then you need to pass null for
the namespace URI to that method:
<http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-745549614>


Aha...
I just checked Opera with setAttribute() instead of setAttributeNS()
and it eats it too. Still I feel a bit uneasy to create viewBox or
preserveAspectRatio like some vspace/hspace - but it can be just my
paranoia :-)
I think the explicit "no-name space" over setAttributeNS(null,a,v) is
the best (?)

By any chance: do you know what standards say to do if namespace is not
defined or attribute is not defined in this namespace? Like
setAttributeNS(someNS,"foobar",100) or
setAttributeNS("foobar",width,100). Does it suppose to fall into
"no-name" space or crash? (Just thinking to save on a uniform
constructor).

I'm not asking to find the info - I can do it myself of course. But if
you know an immediate answer...

Jan 9 '06 #10

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

Similar topics

10
by: Noozer | last post by:
Is it possible to detect where on a page the click occurred when the OnClick event of the BODY tag is fired? Thx
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...
6
by: Dan | last post by:
I was visiting csszengarden.com and noticed that the blossoms.jpg image in the lower right corner does not appear in Firefox 1.5. It does appear in previous versions of Firefox, and even IE6! Any...
3
by: Victor | last post by:
I was thinking about an easy to determine if cookies are set or not in ASP. I began thinking about how the Session ID is dependent upon a cookie - right? Well, I disabled cookies in Firefox and...
4
by: Uldis Bojars | last post by:
Hi! How can Javascript code detect if a user has been authenticated to see a page, that is, if he has entered a username and password for HTTP authentification to see the current page. Possibly...
7
by: buntyindia | last post by:
I have the following scrollable table I have to implemet a functionality that I can select a row in it & display that data in popup window.. Any hints/example or similar available implementation?...
24
by: dE|_ | last post by:
I have started looking into scripts for screen size detect with the intention of using them to pick from a number of CSS style sheets tailored to the size. Is there a good reason why this is not...
4
by: vunet | last post by:
When user enlarges font with Ctrl+ I want to increase the dimensions of my fixed sized div. IE7 uses zoom-in, so it will increase div dimensions automatically. Firefox, however, increases font...
5
by: hannie | last post by:
onKeyPress does not work in Firefox. If use tab to navigate each field and press "Enter" on "Next" button to submit form and process to the next form / page, IE works well even if without onKeyPress...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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:
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...
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...

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.