This script fails, can't debug the problem (has some TCL in it sorry)

P

Phil Powell

[SCRIPT]
<script type=\"text/javascript\">
<!--

var browserArray = new Array(\"Microsoft Internet Explorer\",
\"Netscape\");

if (browserArray.in_array(navigator.appName, browserArray) &&
navigator.appName == \"Microsoft Internet Explorer\" &&
parseInt(navigator.appVersion) >= 4
) { // IE USERS

var url = \"http://$serverName\";
var title = \"[regsub {"} $brand {\&quot;} newBrand; set
newBrand]\";

document.write(' <A
Href=\"javascript:window.external.AddFavorite(url, title);\" return
true;');
document.writeln('\">${smFont}BOOKMARK ' +
title.toUpperCase().replace(new RegExp(/(ä)|ä/),
String.fromCharCase(228)) + '</font></a>');

} else if (browserArray.in_array(navigator.appName, browserArray))
{ // NETSCAPE, ETC USE CTRL-D

document.writeln('${smFont}PRESS (CTRL-D) TO BOOKMARK ' +
title.toUpperCase().replace(new RegExp(/(ä)|ä/),
String.fromCharCase(228)) + '</font>');

}
document.writeln(' |');

//-->
</script>
[/SCRIPT]

When run, this script fails to recognize the correct browser; I'll be
in IE and it'll think it's not IE.

When also run, this script fails to replace "ä" with
String.fromCharCase(228) as well.

Please help, it's affecting a live site

Thanx
Phil
 
V

VK

Phil said:
[SCRIPT]
<script type=\"text/javascript\">
<!--

var browserArray = new Array(\"Microsoft Internet Explorer\",
\"Netscape\");

Why do you think it's going to be IE or NN only? Actually the chance to
meet NN now is *much* lower than other browsers like say Firefox.

It would be good enough just
if ((window.external)&&(window.external.AddFavorite)) {
// then use IE-exclusive AddFavorite method
}

And how enyone suppose to guess where characters escaped for your TCL
pre-processor and where it's a malformed JavaScript string?

Please serve the page of question in a browser, View Source > Copy >
Paste in your next message. Otherwise it will remain a difficult
guessing game.
 
T

Thomas 'PointedEars' Lahn

Phil said:
<script type=\"text/javascript\">
<!--

Commenting out script element content this way has always been
nonsense, and is obsolete since about six years. Search the archives.
var browserArray = new Array(\"Microsoft Internet Explorer\",
\"Netscape\");

I take it that the script is generated by some kind of server-side
application, as it is not at all syntactically correct as it is.
If so, you should post the generated source code (or the public URL
of it if there is one), not the generating one, as only the former
is relevant for client-side scripts.
if (browserArray.in_array(navigator.appName, browserArray) &&
navigator.appName == \"Microsoft Internet Explorer\" &&
parseInt(navigator.appVersion) >= 4
) { // IE USERS
[...]

Utter nonsense. <URL:http://pointedears.de/scripts/test/whatami>.


PointedEars
 
R

Randy Webb

VK said the following on 4/16/2006 1:54 PM:
Phil said:
[SCRIPT]
<script type=\"text/javascript\">
<!--

var browserArray = new Array(\"Microsoft Internet Explorer\",
\"Netscape\");

Why do you think it's going to be IE or NN only? Actually the chance to
meet NN now is *much* lower than other browsers like say Firefox.

It would be good enough just
if ((window.external)&&(window.external.AddFavorite)) {
// then use IE-exclusive AddFavorite method
}

Did you test that? It is well known, to some of us anyway, that you can
not reliably test for addfavorite (it is case insensitive - test it).
 
P

Phil Powell

Thomas said:
Phil said:
<script type=\"text/javascript\">
<!--

Commenting out script element content this way has always been
nonsense, and is obsolete since about six years. Search the archives.
var browserArray = new Array(\"Microsoft Internet Explorer\",
\"Netscape\");

I take it that the script is generated by some kind of server-side
application, as it is not at all syntactically correct as it is.
If so, you should post the generated source code (or the public URL
of it if there is one), not the generating one, as only the former
is relevant for client-side scripts.
if (browserArray.in_array(navigator.appName, browserArray) &&
navigator.appName == \"Microsoft Internet Explorer\" &&
parseInt(navigator.appVersion) >= 4
) { // IE USERS
[...]

Utter nonsense. <URL:http://pointedears.de/scripts/test/whatami>.

Your URL displays nothing.
 
P

Phil Powell

VK said:
Phil said:
[SCRIPT]
<script type=\"text/javascript\">
<!--

var browserArray = new Array(\"Microsoft Internet Explorer\",
\"Netscape\");

Why do you think it's going to be IE or NN only? Actually the chance to
meet NN now is *much* lower than other browsers like say Firefox.

It would be good enough just
if ((window.external)&&(window.external.AddFavorite)) {
// then use IE-exclusive AddFavorite method
}

And how enyone suppose to guess where characters escaped for your TCL
pre-processor and where it's a malformed JavaScript string?

Please serve the page of question in a browser, View Source > Copy >
Paste in your next message. Otherwise it will remain a difficult
guessing game.


<script type="text/javascript">
<!--

var browserArray = new Array("Microsoft Internet Explorer",
"Netscape");


if (browserArray.in_array(navigator.appName, browserArray) &&
navigator.appName == "Microsoft Internet Explorer" &&
parseInt(navigator.appVersion) >= 4
) { // IE USERS

var url = "http://valsignalandet.com";
var title = "Välsignalandet";

document.write(' <A
Href="javascript:window.external.AddFavorite(url, title);" return
true;');
document.writeln('"><font face="Georgia, Verdana, Arial, Helvetica,
sans-serif" size="1"><b>BOOKMARK ' + title.replace(new
RegExp(/ä/), String.fromCharCase(197)).toUpperCase() +
'</font></a>');

} else if (browserArray.in_array(navigator.appName, browserArray))
{ // NETSCAPE, ETC USE CTRL-D

document.writeln('<font face="Georgia, Verdana, Arial, Helvetica,
sans-serif" size="1"><b>PRESS (CTRL-D) TO BOOKMARK ' +
title.replace(new RegExp(/ä/),
String.fromCharCase(197)).toUpperCase() + '</font>');

}
document.writeln(' |</a>');


//-->
</script>
<noscript>
<font face="Georgia, Verdana, Arial, Helvetica, sans-serif"
size="1"><b>PRESS (CTRL-D) TO BOOKMARK VäLSIGNALANDET AS
"http://valsignalandet.com"</font> |
</noscript>
 
P

Phil Powell

Thomas said:
Commenting out script element content this way has always been
nonsense, and is obsolete since about six years. Search the archives.

They need to replace Simon Cowell with you. You'll make tons more
money for pointing out nonissues than you will on me. Translation:
Commenting out script element content breaks absolutely nothing and has
not been even officially deprecated by any client browser of any kind.
Could you please stick with what is breaking my code?
I take it that the script is generated by some kind of server-side
application, as it is not at all syntactically correct as it is.
If so, you should post the generated source code (or the public URL
of it if there is one), not the generating one, as only the former
is relevant for client-side scripts.

See my reply to VK.
if (browserArray.in_array(navigator.appName, browserArray) &&
navigator.appName == \"Microsoft Internet Explorer\" &&
parseInt(navigator.appVersion) >= 4
) { // IE USERS
[...]

Utter nonsense. <URL:http://pointedears.de/scripts/test/whatami>.

Why is it so?
 
V

VK

Randy said:
Did you test that? It is well known, to some of us anyway, that you can
not reliably test for addfavorite (it is case insensitive - test it).

As it happens rather often, I missed the source of you excitement
completely. I did not propose to change the case: I proposed to make
feature test instead of looking for browser name in the UA's string:
if ((window.external)&&(window.external.AddFavorite)) { ...

And yes (but irrelevant) AddFavorite method is not case sensitive: but
the official method description uses AddFavorite, not addfavorite:
<http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/addfavorite.asp>
IMHO it is always better to use the officialy described syntax rather
than explore system's durt tolerance.

To OP: here is also a sniffing-free variant:

<html>
<head>
<title>Bookmark</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
</head>

<body>

<!--[if IE]>
<p>
<a href="NoScript.html"
onclick="
event.returnValue = false;
external.AddFavorite(location.href,document.title)">Add to
favorites</a>
</p>
<![endif]-->
<![if !IE]>
<p>Press Ctrl+D to bookmark this page</p>
<![endif]>

</body>
</html>
 
P

Phil Powell

Randy said:
VK said the following on 4/16/2006 1:54 PM:
Phil said:
[SCRIPT]
<script type=\"text/javascript\">
<!--

var browserArray = new Array(\"Microsoft Internet Explorer\",
\"Netscape\");

Why do you think it's going to be IE or NN only? Actually the chance to
meet NN now is *much* lower than other browsers like say Firefox.

It would be good enough just
if ((window.external)&&(window.external.AddFavorite)) {
// then use IE-exclusive AddFavorite method
}

Did you test that? It is well known, to some of us anyway, that you can
not reliably test for addfavorite (it is case insensitive - test it).

I got it, thanx

title.replace("ä", String.fromCharCode(196)).toUpperCase()

That was all it took for it to work!
Phil
 
L

Lasse Reichstein Nielsen

Phil Powell said:
<script type="text/javascript">
<!--

HTML comment is unneccessary, although not harmful in HTML (it would
be in XHTML, and we can't see which you are using).
var browserArray = new Array("Microsoft Internet Explorer",
"Netscape");


if (browserArray.in_array(navigator.appName, browserArray) &&

Where is the "in_array" function on arrays defined? Why does it take
an array as second argument if it is a method on arrays?
navigator.appName == "Microsoft Internet Explorer" &&
parseInt(navigator.appVersion) >= 4
) { // IE USERS

I too recommend feature detection, not browser detection.
var url = "http://valsignalandet.com";
var title = "Välsignalandet";

document.write(' <A
Href="javascript:window.external.AddFavorite(url, title);" return
true;');

I guess this line was broken by your news client. If you cannot use a
news client that doesn't break lines when it shouldn't, it's recommended
that you restrict lines to ~72 characters. In this case I can see the
problem, since you are copy'n'pasting the exact output of your server
side program ... it's just that that is not what we see.
To use the script we can't just copy it into a page, we have to manually
find and remove the incorrect line breaks ... which is a barrier for
you getting answers, and you don't want that :)

You should not use a link with a "javascript:" URL, but instead use
the onclick attribute. In IE, clicking a javascript:-link will put the
browser into a mode where it expects the page to be unloaded
soon. This, amongst other things, stops animated images from
animating.

I would prefer it as a button, for semantic reasons (links link to
resources, buttons do things, so this matches a button better than a
link).
document.writeln('"><font face="Georgia, Verdana, Arial, Helvetica,
sans-serif" size="1"><b>BOOKMARK ' + title.replace(new
RegExp(/ä/), String.fromCharCase(197)).toUpperCase() +

You are using "title" as a variable. I'm guessing that you refer to
the document's title, which is available as "document.title".

You write "new RegExp(/ä/)". Since "/ä/" is already a RegExp,
the outer call is unnecessary. You probably want to match all instances
of "ä" in the title, so you should use "/ä/g" if there is
more than one.

"String.fromCharCase(197)" should probably be "String.fromCharCode(197)",
or just "Å".
It would me more correct to convert "ä" to "å" (i.e.,
String.fromCharCode(228)). The .toUpperCase() call works correctly on
this.

Is "Å" the only non-ASCII letter you expect to be coded in the page
title? Could it be written as "&Aring;"?

You could consider using:
document.title.replace(/&#(\d+);/g, function(m,n) {
return String.fromCharCode(Number(n));
})
to convert all numeric character entities to the respective characters.
'</font></a>');

I would recommend CSS instead of font tags.

In order to be correct HTML, you should escape the "</" sequence to
"<\/", since the former is what ends the script element according to
the standard. Browsers tend to continue the script element until
the first "</script", though.
} else if (browserArray.in_array(navigator.appName, browserArray))
{ // NETSCAPE, ETC USE CTRL-D

document.writeln('<font face="Georgia, Verdana, Arial, Helvetica,
sans-serif" size="1"><b>PRESS (CTRL-D) TO BOOKMARK ' +
title.replace(new RegExp(/ä/),
String.fromCharCase(197)).toUpperCase() + '</font>');
dittos

}
document.writeln(' |</a>');


If you try to run this, you would get error messages in the javascript
console (in Netscape 4 or Mozilla browsers) or directly as popups
in IE. Have you read the messages there?

/L
 
T

Thomas 'PointedEars' Lahn

Lasse said:
HTML comment is unneccessary, although not harmful in HTML (it would
be in XHTML, and we can't see which you are using).

Of course it is harmful in HTML, too. Because one relies on either a
non-compliant parser to remove those delimiters before the content is
passed to the script engine, or an ECMAScript extension to interpret
those operators differently if they are arranged this way.


PointedEars
 
O

optimistx

Thomas 'PointedEars' Lahn said:
Phil said:
Thomas said:
Phil Powell wrote:
if (browserArray.in_array(navigator.appName, browserArray) &&
navigator.appName == \"Microsoft Internet Explorer\" &&
parseInt(navigator.appVersion) >= 4
) { // IE USERS
[...]

Utter nonsense. <URL:http://pointedears.de/scripts/test/whatami>.

Your URL displays nothing.

A bold lie, of course. But I expected nothing more from you.


PointedEars

I have clicked your link above 4 times during several hours, as you might
see from your server log. My browser shows a blank page with a message
'Done' in the statusbar.

So in your opinion I am a bold liar as Phil Powell?

Interesting. Amusing(?).
 
R

Randy Webb

VK said the following on 4/17/2006 3:30 AM:
As it happens rather often, I missed the source of you excitement
completely. I did not propose to change the case: I proposed to make
feature test instead of looking for browser name in the UA's string:
if ((window.external)&&(window.external.AddFavorite)) { ...

And my point was that if you test that code in your IE you will find out
what I was referring to.

<URL:http://groups.google.com/group/comp...w.external.addfavorite&meta=#433fc52e9d02b7a4>
<URL:http://groups.google.com/group/comp...ndow.external+Richard&rnum=1#9bde8e81844b796d>

Adding the test for AddFavorite bombs it out. Badly. You can test for
window.external but not for .addfavorite
And yes (but irrelevant) AddFavorite method is not case sensitive: but
the official method description uses AddFavorite, not addfavorite:
<http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/addfavorite.asp>
IMHO it is always better to use the officialy described syntax rather
than explore system's durt tolerance.

True but it was more a side-note than anything else.
To OP: here is also a sniffing-free variant:

<!--[if IE]>
<p>
<a href="NoScript.html"
onclick="
event.returnValue = false;
external.AddFavorite(location.href,document.title)">Add to
favorites</a>
</p>
<![endif]-->
<![if !IE]>
<p>Press Ctrl+D to bookmark this page</p>
<![endif]>

</body>
</html>

That is not a variant that works reliably though. The AOL browser will
display, and pass, the IE conditionals but it does not support
external.AddFavorite in any capitalization. The first thread I point to
above explains how to do it in AOL and Ctrl-D doesn't work in AOL either.
 
T

Thomas 'PointedEars' Lahn

optimistx said:
"Thomas 'PointedEars' Lahn" [wrote:]
Phil said:
Thomas 'PointedEars' Lahn wrote:
Phil Powell wrote:
if (browserArray.in_array(navigator.appName, browserArray) &&
navigator.appName == \"Microsoft Internet Explorer\" &&
parseInt(navigator.appVersion) >= 4
) { // IE USERS
[...]

Utter nonsense. <URL:http://pointedears.de/scripts/test/whatami>.
Your URL displays nothing.
A bold lie, of course. But I expected nothing more from you.
[...]

I have clicked your link above 4 times during several hours, as you might
see from your server log.

.... where it would have been very helpful if you said what your IP address
was at the time ...
My browser

.... where it would have been very helpful if you said which one exactly ...
shows a blank page with a message 'Done' in the statusbar.

So in your opinion I am a bold liar as Phil Powell?

Yes, i.e. you are none :) Sorry.

It would appear that only IE is having problems with cgi_buffer now (either
an IE patch or PHP upgrade issue, I assume), which is generating a gzip
response if the Accept-* header says so (and at least with my IE it does).

Only in my IE 6 SP1 on Win2k, the content breaks up in the middle of the
generating client-side script code; probably something similar happens on
WinXP (if I assume that the "NT 5.1" requests can be attributed to one or
both of you two.)

It would also appear that the several trustworthy people I have asked to
test it and who reported no problems whatsoever (which led me to believe
that this was merely a bold lie), either did not see the English version,
or they did not use (the same) IE (version as either of us). As
surprisingly the problem did/does not occur with the German version,
cgi_buffer and IE. I will have to investigate this further. Later.

I have disabled cgi_buffer for this resource now and tested it, so it should
also work with you now. Thank you both for pointing this out to me anyway.


PointedEars
 
P

Phil Powell

Thomas said:
Phil said:
Thomas said:
Phil Powell wrote:
if (browserArray.in_array(navigator.appName, browserArray) &&
navigator.appName == \"Microsoft Internet Explorer\" &&
parseInt(navigator.appVersion) >= 4
) { // IE USERS
[...]

Utter nonsense. <URL:http://pointedears.de/scripts/test/whatami>.

Your URL displays nothing.

A bold lie, of course. But I expected nothing more from you.

So why did you reply anyway? There is no point in replying to someone
you expect - in a drawing-a-conclusion illogical kind of way - to
behave in a pattern you cannot prove but can somehow seemingly deduce,
when lying is expected meaning that the thread is nothing more than a
meaningless exercise in personal self-gratification.

You're entertaining in a dark way, mein freund.

Phil
 
O

optimistx

"Thomas 'PointedEars' Lahn" <[email protected]> kirjoitti viestissä
....
Yes, i.e. you are none :) Sorry.

It would appear that only IE is having problems with cgi_buffer now (either
an IE patch or PHP upgrade issue, I assume), which is generating a gzip
response if the Accept-* header says so (and at least with my IE it does).
....

The empty page was shown by Internet Explorer 6.0.2800.1106, and my ip is
84.239.... .

I appreciate your apology, no bad feelings now.
 
T

Thomas 'PointedEars' Lahn

Phil said:
Thomas said:
Phil said:
Thomas 'PointedEars' Lahn wrote:
Phil Powell wrote:
if (browserArray.in_array(navigator.appName, browserArray) &&
navigator.appName == \"Microsoft Internet Explorer\" &&
parseInt(navigator.appVersion) >= 4
) { // IE USERS
[...]

Utter nonsense. <URL:http://pointedears.de/scripts/test/whatami>.
Your URL displays nothing.
A bold lie, of course. But I expected nothing more from you.

So why did you reply anyway? There is no point in replying to someone
you expect - in a drawing-a-conclusion illogical kind of way - to
behave in a pattern you cannot prove but can somehow seemingly deduce,
when lying is expected meaning that the thread is nothing more than a
meaningless exercise in personal self-gratification.

I have already said I am sorry! What else do you want? Me falling on my
knees before you? Forget it.

I have posted the URL because the document resource it points to explains
to you in my own words why your approach of trying to detecting a browser
and working on the assumption that this detection is correct or viable for
the features it supports is a dangerously nonsensical one, and points to
the article in the FAQ Notes of this newsgroup that explains this further,
among others. I created it and point to it here because this is something
that needs to be pointed out so often to script developers and yet is still
so basic in nature, that I do not like to explain it over and over again.

It is not intended to be and it is not at all "a meaningless exercise in
personal self-gratification". There has been only a minor bug in the
server-side script it generates, which led to this misunderstanding, and
should be fixed now (as I explained).
You're entertaining in a dark way, mein freund.

I am not your friend, and I seriously doubt I ever will be. Besides, if
you attempt to use German to try (and fail) patronizing a speaker of German
as native language such as myself, you should at least be able to write
German words correctly (including capitalization of nouns). Unless you
deliberately want to make a complete fool of yourself, of course.


Score adjusted

PointedEars
 
P

Phil Powell

Thomas said:
Phil said:
Thomas said:
Phil Powell wrote:
Thomas 'PointedEars' Lahn wrote:
Phil Powell wrote:
if (browserArray.in_array(navigator.appName, browserArray) &&
navigator.appName == \"Microsoft Internet Explorer\" &&
parseInt(navigator.appVersion) >= 4
) { // IE USERS
[...]

Utter nonsense. <URL:http://pointedears.de/scripts/test/whatami>.
Your URL displays nothing.
A bold lie, of course. But I expected nothing more from you.

So why did you reply anyway? There is no point in replying to someone
you expect - in a drawing-a-conclusion illogical kind of way - to
behave in a pattern you cannot prove but can somehow seemingly deduce,
when lying is expected meaning that the thread is nothing more than a
meaningless exercise in personal self-gratification.

I have already said I am sorry! What else do you want? Me falling on my
knees before you? Forget it.

I have posted the URL because the document resource it points to explains
to you in my own words why your approach of trying to detecting a browser
and working on the assumption that this detection is correct or viable for
the features it supports is a dangerously nonsensical one, and points to
the article in the FAQ Notes of this newsgroup that explains this further,
among others. I created it and point to it here because this is something
that needs to be pointed out so often to script developers and yet is still
so basic in nature, that I do not like to explain it over and over again.

It is not intended to be and it is not at all "a meaningless exercise in
personal self-gratification". There has been only a minor bug in the
server-side script it generates, which led to this misunderstanding, and
should be fixed now (as I explained).
You're entertaining in a dark way, mein freund.

I am not your friend, and I seriously doubt I ever will be. Besides, if
you attempt to use German to try (and fail) patronizing a speaker of German
as native language such as myself, you should at least be able to write
German words correctly (including capitalization of nouns). Unless you
deliberately want to make a complete fool of yourself, of course.


Score adjusted

Life not fazed.

Phil
 
P

Phil Powell

Thomas said:
Phil said:
Thomas said:
Phil Powell wrote:
Thomas 'PointedEars' Lahn wrote:
Phil Powell wrote:
if (browserArray.in_array(navigator.appName, browserArray) &&
navigator.appName == \"Microsoft Internet Explorer\" &&
parseInt(navigator.appVersion) >= 4
) { // IE USERS
[...]

Utter nonsense. <URL:http://pointedears.de/scripts/test/whatami>.
Your URL displays nothing.
A bold lie, of course. But I expected nothing more from you.

So why did you reply anyway? There is no point in replying to someone
you expect - in a drawing-a-conclusion illogical kind of way - to
behave in a pattern you cannot prove but can somehow seemingly deduce,
when lying is expected meaning that the thread is nothing more than a
meaningless exercise in personal self-gratification.

I have already said I am sorry! What else do you want? Me falling on my
knees before you? Forget it.

I have posted the URL because the document resource it points to explains
to you in my own words why your approach of trying to detecting a browser
and working on the assumption that this detection is correct or viable for
the features it supports is a dangerously nonsensical one, and points to
the article in the FAQ Notes of this newsgroup that explains this further,
among others. I created it and point to it here because this is something
that needs to be pointed out so often to script developers and yet is still
so basic in nature, that I do not like to explain it over and over again.

It is not intended to be and it is not at all "a meaningless exercise in
personal self-gratification". There has been only a minor bug in the
server-side script it generates, which led to this misunderstanding, and
should be fixed now (as I explained).
You're entertaining in a dark way, mein freund.

I am not your friend, and I seriously doubt I ever will be. Besides, if
you attempt to use German to try (and fail) patronizing a speaker of German
as native language such as myself, you should at least be able to write
German words correctly (including capitalization of nouns). Unless you
deliberately want to make a complete fool of yourself, of course.

IF YOU INSIST, MEIN FREUND!! GOTT SEGNE EUCH
ALLE!!!!!!!!!!!!!!!!!!!!!!!!

Phil
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,983
Messages
2,570,187
Members
46,747
Latest member
jojoBizaroo

Latest Threads

Top