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

test for ie or netscape

I have seen some codes that can test for the browser and give values
accordingly. I tried to read the FAQ, but was unable to find a simple
version of this. What I want is

If Netscape-test {
code for netscape users
}

If IE-test {
code for ie users
}

Jul 20 '05 #1
25 3852
On Tue, 3 Feb 2004 14:12:12 -0600, Treetop <tr*****@netfront.net> wrote:
I have seen some codes that can test for the browser and give values
accordingly. I tried to read the FAQ, but was unable to find a simple
version of this.


Why do you want to do this? If you are trying to determine what code *can*
be executed, use feature detection, not browser detection. For example, to
see if document.getElementById() is supported use

if( document.getElementById ) {
}

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #2
I have created a script to send data, text and an image src, to an
iframe. I have code that works for IE, and I have code that works for
Netscape, but I can't find code that works for both. I want the
following

if test-for-netscape {
window.frames['external'].setup(links[aNum]);
}
else {
document.external.setup(links[aNum]);
}
"Michael Winter" <M.******@blueyonder.co.invalid> wrote in message
news:op**************@news-text.blueyonder.co.uk...
On Tue, 3 Feb 2004 14:12:12 -0600, Treetop <tr*****@netfront.net> wrote:
I have seen some codes that can test for the browser and give values accordingly. I tried to read the FAQ, but was unable to find a simple version of this.
Why do you want to do this? If you are trying to determine what code

*can* be executed, use feature detection, not browser detection. For example, to see if document.getElementById() is supported use

if( document.getElementById ) {
}

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to

reply)
Jul 20 '05 #3
In article <bv************@ID-221536.news.uni-berlin.de>,
tr*****@netfront.net enlightened us with...
I have seen some codes that can test for the browser and give values
accordingly. I tried to read the FAQ, but was unable to find a simple
version of this. What I want is


And if I use Opera? Or Safari? Or Konqueror? Mac users tend to like
Safari. What about Mozilla? Linux users tend to like Mozilla.
What about if I use Netscape 4? It isn't anything close to Netscape 6 in
regards to what it can do.
How about if I use IE3? It doesn't support half the stuff IE5 does.

Don't test for browsers. You'll end up coming back here wondering why
your code doesn't work in Netscape 8 when it comes out or something.
Test for the objects you want to use.
if (document.layers)
// do something with that for NN4
else if (document.all && ! document.getElementById)
// do something with old IE
else if (document.getElementById)
// recent browsers like IE5+, NN6+, Mozilla, Opera...
--
--
~kaeli~
Those who jump off a bridge in Paris... are in Seine.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 20 '05 #4

"kaeli" <ti******@NOSPAM.comcast.net> wrote in message
news:MP************************@nntp.lucent.com...
In article <bv************@ID-221536.news.uni-berlin.de>,
tr*****@netfront.net enlightened us with...
I have seen some codes that can test for the browser and give values accordingly. I tried to read the FAQ, but was unable to find a simple version of this. What I want is

And if I use Opera? Or Safari? Or Konqueror? Mac users tend to like
Safari. What about Mozilla? Linux users tend to like Mozilla.
What about if I use Netscape 4? It isn't anything close to Netscape

6 in regards to what it can do.
How about if I use IE3? It doesn't support half the stuff IE5 does.

Don't test for browsers. You'll end up coming back here wondering why your code doesn't work in Netscape 8 when it comes out or something.
Test for the objects you want to use.
if (document.layers)
// do something with that for NN4
else if (document.all && ! document.getElementById)
// do something with old IE
else if (document.getElementById)
// recent browsers like IE5+, NN6+, Mozilla, Opera...


I need to have a way to test for IE5+ versus NN6+.
For my code to work for NN6 I need the following:

window.frames['external'].setup(links[aNum]);
For IE6 I need the following:

document.external.setup(links[aNum]);

Jul 20 '05 #5
In article <bv************@ID-221536.news.uni-berlin.de>,
tr*****@netfront.net enlightened us with...

I need to have a way to test for IE5+ versus NN6+.
I bet you don't.


For my code to work for NN6 I need the following:

window.frames['external'].setup(links[aNum]);
For IE6 I need the following:

document.external.setup(links[aNum]);


That makes no sense to me without a context.

Are you trying to call a function resident (defined) in another frame of
a frameset?
If so, the following is mine (well, it's HVMenu's really) and it works
on both IE5+ and NN6+.
It is called from the "main" frame of a 3 frame (top, left, main)
layout. It calls a function defined in the 'left' frame from the 'main'
frame.

if(parent.frames[0]&&parent.frames['leftFrame'].Go)
{
parent.frames['leftFrame'].Go();
}

If that's the kind of thing you're trying, tell me more about your frame
layout and what frame is calling what function and what frame name that
function is in.

--
--
~kaeli~
A backward poet writes... inverse.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 20 '05 #6
On Tue, 03 Feb 2004 20:39:38 GMT, Treetop <tr*****@netfront.net> wrote:
I have created a script to send data, text and an image src, to an
iframe. I have code that works for IE, and I have code that works for
Netscape, but I can't find code that works for both. I want the
following

if test-for-netscape {
window.frames['external'].setup(links[aNum]);
}
else {
document.external.setup(links[aNum]);
}


I don't know if this will work, but give it a shot:

var ifExternal = null;

if( window.frames['external'] ) {
ifExternal = window.frames['external'];
} else if( document.external ) {
ifExternal = window.external;
}

if( ifExternal ) {
ifExternal.setup( links[ aNum ]);
}

The need for the two different code paths seems to be because IE (and
Opera) don't include IFRAMEs in the frames collection, though they do
support the frames collection in general (or seem to).

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #7
I have read the following message from "Treetop" <tr*****@netfront.net>
and have decided to lend my vast knowledge.

The writer said:
I have seen some codes that can test for the browser and give values
accordingly. I tried to read the FAQ, but was unable to find a simple
version of this. What I want is

If Netscape-test {
code for netscape users
}

If IE-test {
code for ie users
}


and my reply is:
Do a Google search on "browser sniffer"

--
Dennis M. Marks
http://www.dcs-chico.com/~denmarks/
Replace domain.invalid with dcsi.net
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 20 '05 #8
OK he it goes...... Some of my clients are local contractors /
construction companies. They like to have images to show off current
and past projects. Most of the time it involves an image and some
text to explain what picture is. The last update I did was over 70
images. I decided to have a blank page that could be updated with a
link, that would put the source for the image and text for the image
on that page, to save me time creating 70 pages. I was unable to find
a way and had to create 70 pages. Not fun.

Today I finally put enough information together from different sources
to create the following code in two pages. I don't like they way I
trick the system into using the correct code. I also don't have a way
to test other browsers other than IE and Netscape. This code works on
my sytem in both IE 6 and Netscape 7.02.

Netscape uses this code:
window.frames['external'].setup(links[aNum]);}

IE uses this code:
document.external.setup(links[aNum]);

index page:

<table border="1" width="600">
<tr valign="top">
<td width="200">

<script language="javascript" type="text/javascript">

var links=new Array();
links[4]=new Array("pic1.jpg","pic1 link text","text for pic1");
links[3]=new Array("pic2.jpg","pic2 link text","text for pic2");
links[2]=new Array("pic3.jpg","pic3 link text","text for pic3");
links[1]=new Array("pic4.jpg","pic4 link text","text for pic4");

function showImg(aNum)
{
if (navigator.appName.substring(0, 7) != "Microso"){
window.frames['external'].setup(links[aNum]);}
else {
document.external.setup(links[aNum]);
}
};
for (var i=links.length-1;i>=0;i--)
{
document.write('<a href="#" onclick=showImg("'+i+'")>' + links[i][1] +
'</a><br>');
}

</script>

</td>
<td align="center" width="500">
<iframe name="external" id="external" style="width:100%;height:500px"
src="picture.html"></iframe>
</td></tr></table>


here is the code in the pictrure.html file

<script language="javascript">
function setup(aLink)
{
document.getElementById("pic").src=aLink[0];
document.getElementById("title").innerHTML=aLink[2];
}
</script>
</head>
<body>

<center>
<img src="pic1.jpg" id="pic">
<p id="title">Text for Pic1</p>
</center>

Jul 20 '05 #9
OK he it goes...... Some of my clients are local contractors /
construction companies. They like to have images to show off current
and past projects. Most of the time it involves an image and some
text to explain what picture is. The last update I did was over 70
images. I decided to have a blank page that could be updated with a
link, that would put the source for the image and text for the image
on that page, to save me time creating 70 pages. I was unable to find
a way and had to create 70 pages. Not fun.

Today I finally put enough information together from different sources
to create the following code in two pages. I don't like they way I
trick the system into using the correct code. I also don't have a way
to test other browsers other than IE and Netscape. This code works on
my sytem in both IE 6 and Netscape 7.02.

Netscape uses this code:
window.frames['external'].setup(links[aNum]);}

IE uses this code:
document.external.setup(links[aNum]);

index page:

<table border="1" width="600">
<tr valign="top">
<td width="200">

<script language="javascript" type="text/javascript">

var links=new Array();
links[4]=new Array("pic1.jpg","pic1 link text","text for pic1");
links[3]=new Array("pic2.jpg","pic2 link text","text for pic2");
links[2]=new Array("pic3.jpg","pic3 link text","text for pic3");
links[1]=new Array("pic4.jpg","pic4 link text","text for pic4");

function showImg(aNum)
{
if (navigator.appName.substring(0, 7) != "Microso"){
window.frames['external'].setup(links[aNum]);}
else {
document.external.setup(links[aNum]);
}
};
for (var i=links.length-1;i>=0;i--)
{
document.write('<a href="#" onclick=showImg("'+i+'")>' + links[i][1] +
'</a><br>');
}

</script>

</td>
<td align="center" width="500">
<iframe name="external" id="external" style="width:100%;height:500px"
src="picture.html"></iframe>
</td></tr></table>


here is the code in the pictrure.html file

<script language="javascript">
function setup(aLink)
{
document.getElementById("pic").src=aLink[0];
document.getElementById("title").innerHTML=aLink[2];
}
</script>
</head>
<body>

<center>
<img src="pic1.jpg" id="pic">
<p id="title">Text for Pic1</p>
</center>
Jul 20 '05 #10
Dennis M. Marks wrote:
I have seen some codes that can test for the browser and give values
accordingly. I tried to read the FAQ, but was unable to find a simple
version of this. What I want is


and my reply is:
Do a Google search on "browser sniffer"


Maybe; but the discussion as I perceive it tends towards object
detection, not browser sniffing.

Er, I don't want to start a war here, if this is still opiniated matter,
I'm out.
--
Bas Cost Budde
http://www.heuveltop.nl/BasCB

Jul 20 '05 #11
>>I need to have a way to test for IE5+ versus NN6+.

I bet you don't.


Maybe this should/could read: I know a way for IE5, and I know a
(different) way for NN6, and I'm looking for any reliable way to
distinguish between the two possibilities.

I, personally, wouldn't want to drop in the gap when both tests for IE5
and NN6 fail. That convinced me to use object detection, not browser
sniffing.

--
Bas Cost Budde
http://www.heuveltop.nl/BasCB

Jul 20 '05 #12
"Michael Winter" <M.******@blueyonder.co.invalid> wrote in message
news:op**************@news-text.blueyonder.co.uk...
<snip>
The need for the two different code paths seems to be because
IE (and Opera) don't include IFRAMEs in the frames collection,
though they do support the frames collection in general
(or seem to).


IE and Opera do make IFRAMEs members of the frames collection. By
integer index and NAME attribute, ID attributes are more problematic and
for cross-browser scripting NAME attributes are preferred, though they
may be doubled up with corresponding ID attributes if needed.

Richard.
Jul 20 '05 #13

"Richard Cornford" <Ri*****@litotes.demon.co.uk> wrote in message
news:bv*******************@news.demon.co.uk...
"Michael Winter" <M.******@blueyonder.co.invalid> wrote in message
news:op**************@news-text.blueyonder.co.uk...
<snip>
The need for the two different code paths seems to be because
IE (and Opera) don't include IFRAMEs in the frames collection,
though they do support the frames collection in general
(or seem to).
IE and Opera do make IFRAMEs members of the frames collection. By
integer index and NAME attribute, ID attributes are more problematic

and for cross-browser scripting NAME attributes are preferred, though they may be doubled up with corresponding ID attributes if needed.

Richard.


What do you recommend I use then to make this work? If you have an
example of code would be wonderful.
Jul 20 '05 #14

"Bas Cost Budde" <ba*@heuveltop.org> wrote in message
news:bv**********@news2.solcon.nl...
I need to have a way to test for IE5+ versus NN6+.
I bet you don't.


Maybe this should/could read: I know a way for IE5, and I know a
(different) way for NN6, and I'm looking for any reliable way to
distinguish between the two possibilities.

I, personally, wouldn't want to drop in the gap when both tests for

IE5 and NN6 fail. That convinced me to use object detection, not browser
sniffing.


What do you recommend I use then to make this work? If you have an
example of code would be wonderful.
Jul 20 '05 #15
On Tue, 3 Feb 2004 22:51:44 -0000, Richard Cornford
<Ri*****@litotes.demon.co.uk> wrote:
"Michael Winter" <M.******@blueyonder.co.invalid> wrote in message
news:op**************@news-text.blueyonder.co.uk...
<snip>
The need for the two different code paths seems to be because
IE (and Opera) don't include IFRAMEs in the frames collection,
though they do support the frames collection in general
(or seem to).


IE and Opera do make IFRAMEs members of the frames collection. By
integer index and NAME attribute, ID attributes are more problematic and
for cross-browser scripting NAME attributes are preferred, though they
may be doubled up with corresponding ID attributes if needed.


A quick test seemed to indicate that numeric indexes work with IFRAMEs
(forgot to mention that), but NAMEs didn't. Of course now, both work. The
test is the same as before, but re-written so I'm puzzled.

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #16
"Bas Cost Budde" <ba*@heuveltop.org> wrote in message
news:bv**********@news2.solcon.nl...
<snip>
and my reply is:
Do a Google search on "browser sniffer"


Maybe; but the discussion as I perceive it tends
towards object detection, not browser sniffing.

Er, I don't want to start a war here, if this is still
opiniated matter, I'm out.


It is not a matter of opinion, there are no browser detecting techniques
that can reliably tell you whether a browser is, for example, a version
of a Netscape or a Microsoft browser. The non-Microsoft and Netscape
browsers put so much effort into lying about it in their UA strings
and/or reproducing (or faking) the features of more common browsers that
you cannot tell them apart.

Fortunately feature detecting as a technique has no interest in the type
or version of the browser in use so it stops being important that you
cannot tell which browser it is.

Richard.
Jul 20 '05 #17
Treetop wrote:
OK he it goes...... Some of my clients are local contractors /
construction companies. They like to have images to show off current
and past projects. Most of the time it involves an image and some
text to explain what picture is. The last update I did was over 70
images. I decided to have a blank page that could be updated with a
link, that would put the source for the image and text for the image
on that page, to save me time creating 70 pages. I was unable to find
a way and had to create 70 pages. Not fun.


The ideal solution would be server-side. But if you cannot do that for
whatever reason, there are client-side solutions, though they require
Javascript (which doesn't seem to be an issue for you since that's the
tract you are taking anyway). It sounds like you could benefit from
searching the substring in a link, as I've done in the photo gallery of
my softball site:

http://www.wrayvensoftball.com/global/gallery.shtml

Clicking on a thumb invokes a single photo page, which in turn reads the
substring following the ? in the link to determine what image and
caption to display. The images and captions themselves are in an aray in
a simple text file.

It's not too difficult to figure out by looking at the source code of
the various files involved.

--

*** Remove the DELETE from my address to reply ***

================================================== ====
Kevin Scholl http://www.ksscholl.com/
ks*****@comcast.DELETE.net
------------------------------------------------------
Information Architecture, Web Design and Development
------------------------------------------------------
We are the music makers, and we are the dreamers of
the dreams...
================================================== ====
Jul 20 '05 #18

"Treetop" <tr*****@netfront.net> wrote in message
news:bv************@ID-221536.news.uni-berlin.de...
<snip>
What do you recommend I use then to make this work? ...

<snip>

if((window.frames)&&( window.frames['iframeName'])&&
(window.frames['iframeName'].setup)){
window.frames['iframeName'].setup(links[aNum]);
}

-and change the name of the IFRAME so that it is not using the same name
as any existing properties of the window object (such as "external") on
any browsers.

Richard.
Jul 20 '05 #19
"Michael Winter" <M.******@blueyonder.co.invalid> wrote in message
news:op**************@news-text.blueyonder.co.uk...
<snip>
IE and Opera do make IFRAMEs members of the frames collection. ...
<snip>A quick test seemed to indicate that numeric indexes work
with IFRAMEs (forgot to mention that), but NAMEs didn't. Of
course now, both work. The test is the same as before, but
re-written so I'm puzzled.


I was surprised that you didn't find the IFRAME in the frames collection
under its NAME attribute (IDs don't work with Opera <= 6 but should with
later versions). Still I am glad you are finding them now as it means
that the cross-browser approach of accessing named IFRAMEs only as named
members of the frames collection is still valid. I was sure IE 6 hadn't
changed but I haven't got round to installing the latest versions of
Opera 7 yet and they might have changed something.

I think that the OP is possibly shooting himself in the foot a bit using
the name "external" for the IFRAME as IE already has a global property
called "external" (and other browsers may also implement, or spoof, it)
and on many browsers, including IE, the frames collection is a reference
back to the global object anyway.

Richard.

Jul 20 '05 #20
Treetop wrote:
"Bas Cost Budde" <ba*@heuveltop.org> wrote in message
news:bv**********@news2.solcon.nl...
I need to have a way to test for IE5+ versus NN6+.

I bet you don't.


Maybe this should/could read: I know a way for IE5, and I know a
(different) way for NN6, and I'm looking for any reliable way to
distinguish between the two possibilities.

I, personally, wouldn't want to drop in the gap when both tests for


IE5
and NN6 fail. That convinced me to use object detection, not browser
sniffing.

What do you recommend I use then to make this work? If you have an
example of code would be wonderful.


Your solution has already been provided in previous posts:

Instead of :
///////////////////////////////////////////////////////
if (navigator.appName.substring(0, 7) != "Microso")
window.frames['external'].setup(links[aNum]);
else
document.external.setup(links[aNum]);
////////////////////////////////////////////////////////

Do the following:
////////////////////////////////////////////////////////
if( window.frames && window.frames['iframeName'] &&
window.frames['iframeName'].setup)
window.frames['iframeName'].setup(links[aNum]);
else if(document.external && document.external.setup)
document.external.setup(links[aNum]);
/////////////////////////////////////////////////////////

You check for the existence of the feature. For instance, where you
check for the string "Microsoft", I check to see if
window.frames['name'].setup exists. If it exists, that means the
browser supports the feature you want to execute. If not, check the
other method.

By doing it this way, ALL browsers that work the way Microsoft does will
work properly, and ALL browsers that work the way Netscape does will
work properly.

This type of check is similar to other languages that use many
references. For instance, in a C++ function, you would _NEVER_ write
the following code by itself:

object->subObject->property = "test";

Instead, you would make sure everything exists in place for you to do so:

if(object && object->subObject)
object->subObject->property = "test";

I hope this helps,
Brian

Jul 20 '05 #21
Treetop wrote:
What do you recommend I use then to make this work? If you have an
example of code would be wonderful.


It is almost in your original question.
if (window.frames) {
window.frames['external'].setup(links[aNum]);
} else if (document.external) {
document.external.setup(links[aNum]);
}

Maybe add another if for the case both expressions fail. But as long as
you remain within IE5 and NN6 one of them will succeed, so no need.

--
Bas Cost Budde
http://www.heuveltop.nl/BasCB

Jul 20 '05 #22
In article <bv************@ID-221536.news.uni-berlin.de>,
tr*****@netfront.net enlightened us with...
OK he it goes...... Some of my clients are local contractors /
construction companies. They like to have images to show off current
and past projects. Most of the time it involves an image and some
text to explain what picture is. The last update I did was over 70
images. I decided to have a blank page that could be updated with a
link, that would put the source for the image and text for the image
on that page, to save me time creating 70 pages. I was unable to find
a way and had to create 70 pages. Not fun.


Um, why don't you just stick the image name and text descriptions in a
javascript array in a js file, then dynamically write the page based on
that array (include the js file in an html page)? Then all you'd have to
update would be that text js file.
No Iframe required. Just one html page.
You could use the same idea to make a slideshow, where users click on a
link and the image shows up. No frames. Just two divs - one with links
and one where the picture goes.

Obviously you're only really concerned about IE5 and NN6 - it's very
easy to dynamically write elements with createElement and appendChild
with those browsers. That would work in all other DOM browsers, too,
like Opera 7, Mozilla, etc. (I think even Safari)

If you're interested in that solution, I could probably put a little
example together for you.

--
--
~kaeli~
Shotgun wedding: A case of wife or death.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 20 '05 #23

"kaeli" <ti******@NOSPAM.comcast.net> wrote in message
news:MP***********************@nntp.lucent.com...
In article <bv************@ID-221536.news.uni-berlin.de>,
tr*****@netfront.net enlightened us with...
OK he it goes...... Some of my clients are local contractors /
construction companies. They like to have images to show off current and past projects. Most of the time it involves an image and some
text to explain what picture is. The last update I did was over 70 images. I decided to have a blank page that could be updated with a link, that would put the source for the image and text for the image on that page, to save me time creating 70 pages. I was unable to find a way and had to create 70 pages. Not fun.

Um, why don't you just stick the image name and text descriptions in

a javascript array in a js file, then dynamically write the page based on that array (include the js file in an html page)? Then all you'd have to update would be that text js file.
No Iframe required. Just one html page.
You could use the same idea to make a slideshow, where users click on a link and the image shows up. No frames. Just two divs - one with links and one where the picture goes.

Obviously you're only really concerned about IE5 and NN6 - it's very
easy to dynamically write elements with createElement and appendChild with those browsers. That would work in all other DOM browsers, too,
like Opera 7, Mozilla, etc. (I think even Safari)

If you're interested in that solution, I could probably put a little
example together for you.


If you don't mind, I would love to see an example of this. I am very
novice to JavaScript and need all the help I can get.

Jul 20 '05 #24
In article <bv************@ID-221536.news.uni-berlin.de>,
tr*****@netfront.net enlightened us with...


If you don't mind, I would love to see an example of this. I am very
novice to JavaScript and need all the help I can get.


This is really, really basic and shoves them all together.
You'd need to pretty it up with breaks and stuff.
Tested successfully in IE6, NN7, and Opera 7.
(Acknowledgement to www.alistapart.com for giving me the pipe separated
array idea instead of a clunky 2-dim array)

-------------------------
/*
jsImages.js
Has array of images and descriptions in .
Modify as needed.
The format is image name, separated by a pipe character ("|") followed
by the description. The last one doesn't have a comma; all others do.
*/

var imgArray = new Array(
"tri.gif|This is a triangle gif that points up.",
"tridown.gif|This is a triangle gif that points down.",
"trileft.gif|This is a triangle gif that points left."
);

-------------------------
test.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<title> New Document </title>
<script type="text/javascript" language="javascript" src="jsImages.js">
</script>
</head>

<body>
<p>Hi there. This is a test of the dynamic image writer!</p>

<script type="text/javascript" language="javascript">
if (document.createElement && document.appendChild)
{
var L = imgArray.length;
for(i=0; i<L; i++)
{
pieces = imgArray[i].split('|');
img = document.createElement('img');
img.setAttribute('src',pieces[0]);
img.setAttribute('alt',pieces[1]);
document.body.appendChild(img);
}
}
else alert("Oh, no, imcompatible browser!");
</script>
</body>
</html>
--
--
~kaeli~
Synonym: the word you use in place of a word you can't
spell.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 20 '05 #25
JRS: In article <bv************@ID-221536.news.uni-berlin.de>, seen in
news:comp.lang.javascript, Treetop <tr*****@netfront.net> posted at Tue,
3 Feb 2004 14:12:12 :-
I have seen some codes that can test for the browser and give values
accordingly. I tried to read the FAQ, but was unable to find a simple
version of this.


FAQ 4.26 deals with this question.

But the example presented does not show alternatives.

ISTM that it would be better to show an example of a function that
returns a reference-to-object, something like

function GROb(ID) {
if (document.getElementById) return document.getElementById(ID)
if (document.all) return document.all[ID]
if (document.layers) return ...???...
return null // useless browser
}

which shows doing something in different ways ;

and maybe

if ( !document.getElementById ) {
if ( document.all ) {
document.getElementById = function(id) {
return document.all[id] } }
if (document.layers( { ... }
}
if ( !document.getElementById ) alert("It'll never work!")

which shows conditionally implementing a missing standard function.

That may not be the best choice for this demonstration.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 20 '05 #26

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

Similar topics

2
by: Robert Oschler | last post by:
I'd like to be able to see if a URL was functional before I attempt to put it in an IFrame. Is there a way to do this so I can prevent the user from ending up with a 404 error page in the IFrame?...
3
by: viza | last post by:
Hi! I use the onscroll event to make something like the CSS position:fixed; for MSIE. In MSIE/5.5, before a function is assigned to the event handler, it has the value null. In Opera, it is...
133
by: Alan Silver | last post by:
Hello, Just wondered what range of browsers, versions and OSs people are using to test pages. Also, since I don't have access to a Mac, will I have problems not being able to test on any Mac...
5
by: Martijn Saly | last post by:
I'd like to test in my script, if it's going to be possible to enable priviliges. If I use this... netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect") ....it presents a...
60
by: marss | last post by:
Maybe anyone know good free online JavaScript knowledge test? This not exactly a system for testing online required - it may be simply list of questions with variants of answers (I have to prepare...
2
by: emily224 | last post by:
Hello, I have been trying to understand this source code, which I retreived from my online course test. I would like to know how to find the answer for the question on the test. Im sure the answer...
4
by: emily224 | last post by:
Hello, I have been trying to understand this source code, which I retreived from my online course test. I would like to know how to find the answer for the question on the test. Im sure the answer...
6
by: Aaron Gray | last post by:
Hi, I know the 'document.getElementById()' issue is really over since every browser since 1998 supports the W3C DOM standard, but I could not resist this offering :- if...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
1
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...
0
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...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.