[Javascript] Netscape object model : forms in div/layer

Rodney Myers rmyers at i-way.co.uk
Thu Apr 19 10:31:38 CDT 2001


Chris,

Thanks for the reply.
It has to be something like that, but it did not work just like that.
I would really still like to get this sorted for other purposes.

I tried :

a) Checking for further layers nested inside - and found a layer, called
something else naturally, and substituted that name in the [] - no go.
b) I added window. in front of document and that did not help.

I thought if Nescpae users were clever enough to be using layers then
they did not need my script to tell them they hade left out the form
tags ...(maybe!)

This worked, in the sense that no alert was generated :

function isForm(){
// Any form on this page?
if(window.document.forms.length==0 && !(is.ns &&
window.document.layers.length>0 ) )
	{
	alert('Whoops! : NO FORM! : CHECK PAGE for <form>..</form> tags');
	}

}//


// BrowserCheck Object
function BrowserCheck() {
	var b = navigator.appName
	if (b.indexOf("Netscape")>-1){ this.b = "ns";}
	else if (b=="Microsoft Internet Explorer") this.b = "ie"
	else this.b = b
	this.version = navigator.appVersion
	this.v = parseInt(this.version)
	this.ns = (this.b=="ns" && this.v>=4)
	this.ns4 = (this.b=="ns" && this.v==4)
	this.ns5 = (this.b=="ns" && this.v==5)
	this.ie = (this.b=="ie" && this.v>=4)
	this.ie4 = (this.version.indexOf('MSIE 4')>0)
	this.ie5 = (this.version.indexOf('MSIE 5')>0)
	this.min = (this.ns||this.ie)
}
var is = new BrowserCheck();



function BrowserCheck() is Dan Steinman's
But I modified this line :
if (b.indexOf("Netscape")>-1){ this.b = "ns";}
from
if (b=="Netscape")... because that breaks down on badged editions.




Chris Basken wrote:
> 
> the problem is: NS4.x sees a layer as its own document, so try...
> 
>         document.layers['LayoutLYR'].document.forms.length
> 
> this will, of course, crash IE.  thank you, have a nice flight.
> 
> my final solution was to write a function that cycled through the layers (if
> any) and searched for forms in them.  if it found one, it would assign it to
> an element in an array.  i would also do this for IE, but simply replicate
> document.forms into my array.  once that was done, i could reference any
> form on the page by using my array, and it would work for NS and IE.
> 
> >
> > A client using one of my form processing scripts starts his document
> > body with
> >
> >     <div ID="LayoutLYR"><layer ID="LayoutLYR" ...>
> >
> >
> > In consequence, in Netscape, this test
> > - intended to ensure that the <FORM> </FORM> tags
> >   were not forgotten when building the page - fails:
> >
> > function isForm(){
> > // Any form on this page?
> > if(window.document.forms.length==0)
> >       {
> >       alert('Whoops! : NO FORM! : CHECK PAGE for <form>..</form> tags');
> >       }
> > }
> >
> > The good news is that the main part of the scripts operated OK since
> > they pass their objects to my functions.
> >
> > I am not surprised, but I am frustrated that I cannot yet find the
> > information on how Netscape wants the forms addressed in its object
> > model.
> >
> > Can anyone point me at a good reference for this?
> >


Courses in April 
Mon 23  : Making a Start in E-Commerce with Shop at ssistant
Tue 24  : Meeting Business Needs with the Shop at ssistant Classic system
Wed 25 : Building Better Shopping Pages with Shop at ssistant Classic


Booking for these Shop at ssistant Classic courses at 
http://www.shopassistant.net/training/  
Or call 01256 880770

Rodney Myers
Based in Oxford, England
Technical Director, Shop at ssistant eCommerce Solutions




More information about the Javascript mailing list