Forum Moderators: open
Is it necessary to include document.all[id] to supoport IE4
and furthermore is there need of braces when using if, if else or is used correct here and is the function well written thus correct syntax?
function replacer(){
var isIe = (navigator.appName == "Microsoft Internet Explorer");
var isOpera = (/opera/i.test(navigator.userAgent));
if(isOpera ¦¦ isIe) {
alert("ie or Opera");
self.location.replace("thispage.html");
}}
function doIterate(){
if (document.getElementsById)
x = document.getElementsById('backToThumbs');
else if (document.all)
// IE4
x = document.all['backToThumbs'];
x.onclick = replacer;
}
addEvent (window,'load',doIterate)
I think you are referring to document.getElementById? Since ID's must be unique there can only be one per document, so the element is singular!
There is however a getElementsByTagName which allows you to build an array of the elements of a certain tag.
To answer your question, you do need to use document.all to support IE4... You can get away without using braces, but I think that the use of them makes for cleaner code...
HTH
}}
function doIterate(){
if (document.getElementById)
x = document.getElementById('backToThumbs');
else if (document.all)
// IE4
x = document.all['backToThumbs'];
x.onclick = replacer;
}
addEvent (window,'load',doIterate)
should the var be set to null at the end of the function (to save a little bandwidth)
unction doIterate(){
if (document.getElementById)
x = document.getElementById('backToThumbs');
else if (document.all)
// IE4
x = document.all['backToThumbs'];
x.onclick = replacer;
x= null;
}
addEvent (window,'load',doIterate)