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

Browser compatibility

I cobbled together the following function from examples on the internet to
set named spanned items in the parent form. It works fine for IE but not at
all for netscape. What other browser conditions do I need to test for and
what is the correct syntax for the
sode so that I am covered for all cases? Thanks!

function WriteContent(name, newText)
{
var browser=navigator.appName
var version=parseInt(navigator.appVersion)

if (browser=="Microsoft Internet Explorer")
eval("self.opener.document.all."+name+".innerHTML= '"+newText+"'");
else
{
self.opener.document.layers[name].document.close();
self.opener.document.layers[name].document.write(newText);
self.opener.document.layers[name].document.close();
}
}
Jul 20 '05 #1
11 5552
In article <3fytb.399968$6C4.164347@pd7tw1no>, "Simon Wigzell"
<si**********@shaw.ca> writes:

I cobbled together the following function from examples on the internet to
set named spanned items in the parent form. It works fine for IE but not at
all for netscape. What other browser conditions do I need to test for and
what is the correct syntax for the
sode so that I am covered for all cases? Thanks!

function WriteContent(name, newText)
{
var browser=navigator.appName
var version=parseInt(navigator.appVersion)
ditch the unreliable .appName and .appVersion
if (browser=="Microsoft Internet Explorer")
eval("self.opener.document.all."+name+".innerHTML= '"+newText+"'");
no eval needed:
self.opener.document.all[name].innerHTML =
else
{
self.opener.document.layers[name].document.close();
self.opener.document.layers[name].document.write(newText);
self.opener.document.layers[name].document.close();
}
}


You cover document.all and document.layers, what about the modern browsers that
use getElementById?

Note the lack of concern about the browser:

function WriteContent(name, newText){
if (document.getElementById)
{
//use getElementById
self.opener.document.getElementById(name).innerHTM L = newText;
//inserting text via innerHTML is inefficient when compared to DOM
//methods.
}
else
{
if (document.all)
{
self.opener.document.all[name].innerHTML = newText;
}
else
{
if (document.layers)
{
//document.layers statements here
}
else
{
alert('You're browser seems not to support dynamic content insertion');
}
}
}

And absolutely *no* concern about what browser it is, but what features it
supports.
http://www.jibbering.com/faq/#FAQ4_26

As a side note:
alert(navigator.appName)

when executed in the AOL browser gives "Microsoft Internet Explorer" but it is
far from being the same browser. And goes to show the fallacy of relying on
..appName when trying to determine my browser.
--
Randy
Jul 20 '05 #2

"HikksNotAtHome" <hi************@aol.com> wrote in message
news:20***************************@mb-m21.aol.com...
In article <3fytb.399968$6C4.164347@pd7tw1no>, "Simon Wigzell"
<si**********@shaw.ca> writes:

I cobbled together the following function from examples on the internet toset named spanned items in the parent form. It works fine for IE but not atall for netscape. What other browser conditions do I need to test for and
what is the correct syntax for the
sode so that I am covered for all cases? Thanks!

function WriteContent(name, newText)
{
var browser=navigator.appName
var version=parseInt(navigator.appVersion)
ditch the unreliable .appName and .appVersion
if (browser=="Microsoft Internet Explorer")
eval("self.opener.document.all."+name+".innerHTML= '"+newText+"'");


no eval needed:
self.opener.document.all[name].innerHTML =
else
{
self.opener.document.layers[name].document.close();
self.opener.document.layers[name].document.write(newText);
self.opener.document.layers[name].document.close();
}
}


You cover document.all and document.layers, what about the modern browsers

that use getElementById?

Note the lack of concern about the browser:

function WriteContent(name, newText){
if (document.getElementById)
{
//use getElementById
self.opener.document.getElementById(name).innerHTM L = newText;
//inserting text via innerHTML is inefficient when compared to DOM
//methods.
}
else
{
if (document.all)
{
self.opener.document.all[name].innerHTML = newText;
}
else
{
if (document.layers)
{
//document.layers statements here
}
else
{
alert('You're browser seems not to support dynamic content insertion'); }
}
}

And absolutely *no* concern about what browser it is, but what features it
supports.
http://www.jibbering.com/faq/#FAQ4_26

As a side note:
alert(navigator.appName)

when executed in the AOL browser gives "Microsoft Internet Explorer" but it is far from being the same browser. And goes to show the fallacy of relying on .appName when trying to determine my browser.
--
Randy


Thanks! Looks like a big improvement on what I had.
Jul 20 '05 #3
"Simon Wigzell" <si**********@shaw.ca> writes:
I cobbled together the following function from examples on the internet to
set named spanned items in the parent form.
The worst part of the internet is that there is no quality control :)
It works fine for IE but not at all for netscape. What other browser
conditions do I need to test for and what is the correct syntax for
the sode so that I am covered for all cases?
All cases would include Javascript not being available, or that
changing the document content isn't possible at all. I guess you are
excluding these cases.
function WriteContent(name, newText)
{
var browser=navigator.appName
var version=parseInt(navigator.appVersion)
If you want to use a property or object, test for it specifically
instead of trying to guess the browser version.

if (browser=="Microsoft Internet Explorer")
eval("self.opener.document.all."+name+".innerHTML= '"+newText+"'");
You should never use eval for accessing properties or variables. You
will probably never need to use eval at all. The exceptions are few
and rare, and it is a safe bet that you won't hit them.
This is (almost) equivalent and *much* more effective:
self.opener.document.all[name].innerHTML=newText;

The "almost" refers to the case where the value of newText contains a
single quote ('). In that case, the eval version fails.
else
{
self.opener.document.layers[name].document.close();
document.layers only exist in Netscape 4. Netscape 6+ is a complete
rewrite (it is a branded version of the Mozilla browser) and is not
compatible with Netscape 4.
self.opener.document.layers[name].document.write(newText);
self.opener.document.layers[name].document.close();
}
}


If newText contains a text string, and not HTML, then use the following:

---
function getElem(doc,id) {
if (doc.getElementById) {
return doc.getElementById(id);
} else if (doc.all) {
return doc.all[id];
} else if (doc.layers) {
return doc.layers[id];
}
return null; // this is not happening
}

function writeContent(name,newText) {
var doc = opener.document;
var elem = getElem(doc,name);
if (doc.createTextNode) { // Modern browsers
var text = doc.createTextNode(newText);
while(elem.hasChildNodes()) {
elem.removeChild(elem.lastChild);
}
elem.appendChild(text);
} else if (elem.innerHTML) { // IE 4
elem.innerHTML = newText; // Maybe use .innerText
} else if (elem.document != doc) { // NS 4
elem.document.open();
elem.document.write(newText);
elem.document.close();
}
}
---
No reference to browser name or version.
If newText contains HTML, you will have to drop the first method,
or parse the HTML yourself.
Tested in Netscape 4, Mozilla FB 0.7, IE 6, and Opera 7

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #4
HikksNotAtHome wrote:

[snip]
if (document.getElementById)
{
//use getElementById
self.opener.document.getElementById(name).innerHTM L = newText;
//inserting text via innerHTML is inefficient when compared to DOM
//methods.
}

[snip]

Where in the DOM standard is innerHTML defined? I can't find it anywhere.

Jul 20 '05 #5
David Leverton <u0*****@abdn.ac.uk> writes:
Where in the DOM standard is innerHTML defined? I can't find it anywhere.


It isn't. The property "innerHTML" was invented by Microsoft. Web
authors liked it, so some other browsers (Mozilla and Opera 7) have
also implemented it to preserve compatability with existing pages.
It is not official DOM.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #6
> Where in the DOM standard is innerHTML defined? I can't find it anywhere.

It is not a standard DOM feature, but it is necessary feature because it give
you access to the HTML parser. It is a Microsoft feature, which has also been
adopted by Mozilla and others.

http://www.crockford.com/

Jul 20 '05 #7
"Douglas Crockford" <no****@laserlink.net> writes:

[innerHTML]
It is not a standard DOM feature, but it is necessary feature because it give
you access to the HTML parser.


I don't see why that is necessary. Handy, yes, but necessary?

I would prefer a function with a type like:
DocumentFragment parseHTML(String)
That would fit much better with the official DOM functions.

Well, maybe in DOM v3 :)

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #8
In article <bp**********@news.abdn.ac.uk>, David Leverton <u0*****@abdn.ac.uk>
writes:
Where in the DOM standard is innerHTML defined? I can't find it anywhere.


You can't find it because its an addon that was initiated by MS and adopted by
several other browser manufacturers.
--
Randy
Jul 20 '05 #9
In article <oe**********@hotpop.com>, Lasse Reichstein Nielsen <lr*@hotpop.com>
writes:
[innerHTML]
It is not a standard DOM feature, but it is necessary feature because it

give
you access to the HTML parser.


I don't see why that is necessary. Handy, yes, but necessary?

I would prefer a function with a type like:
DocumentFragment parseHTML(String)
That would fit much better with the official DOM functions.


I would too. But until one comes about, we are kind of stuck with what we have
to use :-(
--
Randy
Jul 20 '05 #10
Lasse Reichstein Nielsen wrote:
[innerHTML] I would prefer a function with a type like:
DocumentFragment parseHTML(String)
That would fit much better with the official DOM functions.


Though I really like innerHTML, I can only agree to your suggestion.
FWIW, Mozilla has extended the Range model adding several useful
features, like the createContextualFragment method, which does exactly
what you suggest.

<URL: http://www.mozilla.org/docs/dom/domref/dom_range_ref26.html#1005287>
Regards,
Yep.
Jul 20 '05 #11
On Sun, 16 Nov 2003 18:53:40 +0100, Lasse Reichstein Nielsen
<lr*@hotpop.com> wrote:
"Douglas Crockford" <no****@laserlink.net> writes:
It is not a standard DOM feature, but it is necessary feature because it give
you access to the HTML parser.
I don't see why that is necessary. Handy, yes, but necessary?

I would prefer a function with a type like:
DocumentFragment parseHTML(String)
You would also need a serialiser... Which is the other thing it does
of course. DocumentFragment is also problematical (at least it's
proven so in SVG where parseXML exists), then you'd need to provide a
document context, which would mean you'd naturally need the method off
document, or maybe on every single element? none of it sounds that
neat from a JS perspective, I'm sure if it was simple we wouldn't be
waiting until DOM 3 - of course DOM-3 isn't that relevant to HTML
authoring, but in XML based stuff.
That would fit much better with the official DOM functions.


Yes, but remember the official DOM are language agnostic, so they
often have to fit with things that don't make for neat javascript.

Jim.
--
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jul 20 '05 #12

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

Similar topics

4
by: Jez Naisbitt | last post by:
Hi Guys, After a break of 2 years I'm now re-visiting the world of java. I recall on my last foray that I had to stick to java 1.1 so I could deploy applets from a server and obtain maximum...
3
by: Rob Oldfield | last post by:
Just a quick and hopefully straightforward question.... are there any issues with web sites based on .Net not working correctly (or at all) for clients using non IE browsers (Mozilla and Firefox...
4
by: George Hester | last post by:
http://pages.ebay.com/help/new/browser-recommendations.html The reason being that other browsers are just plain buggy. Netscape 6+ surely is. Opera I do not know much about but I hear it can...
3
by: Dot net work | last post by:
Is there a resource on the internet to tell me which javascript can work with which browser. For instance, can I use style.color with all browsers - that kind of thing. Thank you, Regards,...
5
by: Trenqo 0 | last post by:
Instead of doing repetitive checks throughout my code, or defining new methods that won't work unless they are included, I have taken the approach of redefining existing methods in order to make...
2
by: G2 | last post by:
Hi We are dealing with significant browser compatibility issues with Netscape 5.x+ browsers and Mac IE. I am sure most web developers have faced similar issues in the past. Can anyone give me their...
3
by: ms | last post by:
Hi Everyone, You all would be aware of the fact that we boast about .net supporting multiple web browsers. I hope we have all experienced that our screen layouts look different in every other...
4
by: Maxwell2006 | last post by:
Hi, I am struggling with making my website compatible with multiple browsers and versions. Is there any tool that shows me how my pages look like in different browsers
4
by: dreamamit2001 | last post by:
Hi, I would like to know the ASP.NET2.0's(Controls, Menubar, Validations, Object Data Souce Controls, Treeview Control) compatibility with IE5.0 browser on Mac OS. If I don't use Client side...
27
by: David Golightly | last post by:
This is just a quick poll for all you web devs out there: What browsers do you test on/are concerned about compatibility with? Obviously, you're going to test on current-generation browsers such...
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
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
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
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
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,...
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...

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.