test for ie or netscape

B

Brian Genisio

Treetop said:
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
 
D

Dr John Stockton

JRS: In article <[email protected]>, seen in
news:comp.lang.javascript 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.

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.
 
K

kaeli

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.

--
 
T

Treetop

kaeli said:
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.
 
K

kaeli

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.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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top