Forum Moderators: open
But I also seem to be inadvertently hiding the addresses from users of IE5! The following piece of code works with Opera, Mozilla, IE6, IE5.5 and even NN4, but when viewed with IE5 it displays a blank.
function atLast(p1, p2, p3) {
var displayname = 'webmaster';
var mailid = '';
var subject = '';
var href = 'mailto:';
var displaytext = '';
if (p1!= undefined) {
displayname = p1;
}
if (p2!= undefined) {
mailid = p2;
}
if (p3!= undefined) {
subject = p3;
}
if (mailid == '' ) {
href = href + displayname + '@widgets.com';
displaytext = displayname + ' @ widgets.com';
} else {
href = href + mailid + '@widgets.com';
displaytext = displayname;
}
if (subject!= '' ) {
href = href + '?subject=' + subject + '"title="' + subject;
}
document.write('<a href="' + href + '">' + displaytext + '</a>');
}
Any ideas as to what is wrong and what to do about it?
[edited by: korkus2000 at 4:45 pm (utc) on Jan. 19, 2004]
[edit reason] Fixed notification at member request [/edit]
According to my JScript reference, the original form:
if(pl!= undefined){ .. }
would have been OK if *pl* had been declared previously.
Now I'll just paste the ref...
/////////////////////////////////
undefined Property
Returns an initial value of undefined.
Remarks
The undefined property is a member of the Global object, and becomes available when the scripting engine is initialized. When a variable has been declared but not initialized, its value is undefined.
If a variable has not been declared, you cannot compare it to undefined, but you can compare the type of the variable to the string "undefined"
The undefined property is useful when explicitly testing or setting a variable to undefined.
Example
var declared; //Declare variable.
if (declared == undefined) //Test variable.
document.write("declared has not been given a value.");
if (typeOf(notDeclared) == "undefined")
document.write("notDeclared has not been defined.");
Requirements
Version 5.5
See Also
Applies To: Global Object
Looks like IE5 doesn't regard declaring something as a parameter is a previous declaration, while the rest of the world (including IE5.5 and iE6) does.
Incidentally, I've changed the double quotes to single ones in my implementation of the typeof() fix. I seem to remember having problems with this in a previous life (or perhaps about a year ago). The fix is now working.