asp page with browser sniffer doesn't work in Netscape

A

AMC

Hi,

I have the below code in an asp page. When I run this page in IE or Opera it
correctly displays the header info and does not redirect me to 'test.html'.
However, when I run this in Netscape it goes straight to the redirect page
'test.html' which indicates that javascript is not enabled and it also does
not display the header info. Can someone tell me why this is happening?

<%@ Language=VBScript%>
<%'get header info
Response.Write Request.ServerVariables("HTTP_USER_AGENT")

'detect javascript
Set bc = Server.CreateObject("MSWC.BrowserType") %>
Browser Name: <%=bc.browser %>
Browser Version: <%=bc.version%>

<%
if (bc.javascript = FALSE) then
response.write("no javascript")
response.Redirect("Test.html")
else
response.write("has javascript")

end if
set bc=nothing
%>
 
A

Aaron [SQL Server MVP]

Not that anyone uses Netscape anymore, but this is a pretty silly way to
test whether a user has JavaScript enabled, anyway. All you are testing is
that they are using a browser that *supports* JavaScript. They can easily
turn it off, and the test you are doing will still pass.

http://www.aspfaq.com/2058
 
A

AMC

Well,

Plenty of my users still have Netscape so this needs to work. I have
JavaScript enabled in Netscape but the asp page is redirecting to
the test page which indicates that it is not enabled or *supported*. Do you
have any valid information relating to this problem?
 
A

Aaron [SQL Server MVP]

Did you see the link I posted? Use JAVASCRIPT to determine if JavaScript is
enabled, not some stupid browser capabilities object that merely tells you
that JavaScript is SUPPORTED. Do you hire people based solely on what they
say on their resume, or only after they've actually demonstrated that they
can do what they say they can?

--
http://www.aspfaq.com/
(Reverse address to reply.)
 
A

AMC

Duh,

Yes I saw the link you posted, and I am well aware of Browserhawk etc. For
reasons that I won't waste my time explaining again JAVASCRIPT is not an
option.

For your info, the only 'stupidity' is in your inane replies to my post. Who
I hire has no relevance to this thread, but since your asked
I wouldn't hire you because you have clearly demonstrated that you don't
know squat!

Keep posting, and I'll keep laughing!!!
 
B

Bob Lehmann

For reasons that I won't waste my time explaining again JAVASCRIPT is not
an option.
Again? I can't find where you explained it once.

Bob Lehmann
 
R

Rasta

The only question I need answered is why doesn't this script work in
Netscape:




Bob Lehmann said:
not
an option.
Again? I can't find where you explained it once.

Bob Lehmann

AMC said:
Duh,

Yes I saw the link you posted, and I am well aware of Browserhawk etc. For
reasons that I won't waste my time explaining again JAVASCRIPT is not an
option.

For your info, the only 'stupidity' is in your inane replies to my post. Who
I hire has no relevance to this thread, but since your asked
I wouldn't hire you because you have clearly demonstrated that you don't
know squat!

Keep posting, and I'll keep laughing!!!

JavaScript way it
also
 
D

Dave Anderson

AMC said:
if (bc.javascript = FALSE) then
response.write("no javascript")
response.Redirect("Test.html")

Response.Write and Response.Redirect are incompatible:

"Any response body content such as displayed HTML text or
Response.Write text in the page indicated by the original
URL is ignored."

http://msdn.microsoft.com/library/en-us/iissdk/iis/ref_vbom_resomre.asp



--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
 
D

Dave Anderson

Rasta said:
The only question I need answered is why doesn't this script
work in Netscape:

Among other things, because it is being interpreted by IIS (on the server
side), not by Netscape. But let's break it down:


All of the above is immaterial to your question. Leave it out of your post.


The problem with your above approach is that it will not work as expected
unless you keep your browsercap.ini file updated. You will eventually come
to understand that this is more trouble than it is worth, so STOP USING
MSWC.BrowserType NOW.
http://aspfaq.com/show.asp?id=2199

Once you come to terms with this, you should come back and apologize to
Aaron. His initial response was helpful and to the point.



--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
 
M

Morris

AMC said:
Well,

Plenty of my users still have Netscape so this needs to work.
The latest figures I saw suggest that less than 1.5% of users overall
are using Netscape, and that figure is on a steady decline:
http://www.w3schools.com/browsers/browsers_stats.asp
So, apart from the very valid points made by Aaron, if you are spending
more than 1.4% of your project development time on this problem, it
would be time wasted in my book.

Morris
 
D

Dave Anderson

Morris said:
The latest figures I saw suggest that less than 1.5% of users overall
are using Netscape, and that figure is on a steady decline:
http://www.w3schools.com/browsers/browsers_stats.asp
So, apart from the very valid points made by Aaron, if you are
spending more than 1.4% of your project development time on this
problem, it would be time wasted in my book.

He did not say which version of Netscape. Since all versions over 5 are
built on the Gecko engine, this could represent as much as 23.9% of the
market (Firefox + Mozilla + Netscape 7), according to the January 2005
figures on your referenced site. And the share of Gecko-based browsers has
been growing every month for at least a year.


--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
 
M

Morris

Dave said:
He did not say which version of Netscape. Since all versions over 5 are
built on the Gecko engine, this could represent as much as 23.9% of the
market (Firefox + Mozilla + Netscape 7), according to the January 2005
figures on your referenced site. And the share of Gecko-based browsers has
been growing every month for at least a year.

It could represent that number - true. However, since the OP referred to
"Netscape", as opposed to "Mozilla" or "Firefox", I assumed he was
referring to the versions that are declining.

Just goes to illustrate that posters should ensure that they include
*all* relevant information, including version numbers (and that those
trying to reply shouldn't make assumptions - even though they may appear
valid assumptions).

Morris
 
A

Adrienne

Hi,

I have the below code in an asp page. When I run this page in IE or
Opera it correctly displays the header info and does not redirect me to
'test.html'. However, when I run this in Netscape it goes straight to
the redirect page 'test.html' which indicates that javascript is not
enabled and it also does not display the header info. Can someone tell
me why this is happening?

<%@ Language=VBScript%> <%'get header info
Response.Write Request.ServerVariables("HTTP_USER_AGENT")

'detect javascript
Set bc = Server.CreateObject("MSWC.BrowserType") %>
Browser Name: <%=bc.browser %>
Browser Version: <%=bc.version%>

<%
if (bc.javascript = FALSE) then
response.write("no javascript")
response.Redirect("Test.html")
else
response.write("has javascript")

end if
set bc=nothing
%>

In addition to what others have said, browser sniffing is not going to do
you any good. One of reasons is that there are many, many browsers out
there with many different engines, different capabilities, etc. Some
browsers will identify themselves as other than what they are, Opera for
example. Users can also turn javascript off if they so desire.

So the only true way to test for javascript is something like:
<head>
<script type="text/javascript">
location.href="somepage.htm"
</script>
</head>
<body>
<p>Your browser does not seem to have javascript enabled. Please check your
browsers documentation to see if it is available and how to enable it.</p>

Now, if the user never sees the above paragraph, then they have javascript
enabled, otherwise, they don't. Simple.
 

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,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top