Forum Moderators: open

Message Too Old, No Replies

Javascript error with IE5

Not IE5.5 or IE6, nor anything else

         

TheDoctor

9:48 pm on Jan 16, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm trying to hide email addresses from harvesters by the use of Javascript. It seems to be working, in that email addresses hidden this way don't get spammed.

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]

Purple Martin

1:20 am on Jan 17, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Do you get a JavaScript error, and if so what does it say? (You may have to double-click the error icon in the status bar to see it)

What is the code that calls the function? (please post it for us to see)

TheDoctor

1:34 pm on Jan 17, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Aha! Thanks, I didn't know about the error icon.

It doesn't like "undefined". Any suggestions as to how to get around this - other than writing a zillion functons to cover all the possible combinations?

TheDoctor

8:32 pm on Jan 17, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Solution: use
typeof(p1)!= "undefined"

(etc), rather than
p1!=undefined

Thanks again for pointing out the icon to me. Funny how you miss being told about these simple things. Once I found the problem, it took three or four minutes with a manual to try out an alternative approach.

Saintjude

2:53 pm on Jan 18, 2004 (gmt 0)



Just to add...

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

TheDoctor

3:26 pm on Jan 18, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks for this information, Saintjude, and welcome to Webmaster World. May you have a long and happy relationship with the community.

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.