By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,466 Members | 1,172 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,466 IT Pros & Developers. It's quick & easy.

test for ie or netscape

P: n/a
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
Share this Question
Share on Google+
25 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a

"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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
>>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

P: n/a
"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

P: n/a

"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

P: n/a

"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

P: n/a
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

P: n/a
"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

P: n/a
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

P: n/a

"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

P: n/a
"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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a

"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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.