Solved

Checking browser capabilities

Posted on 2010-08-22
9
625 Views
Last Modified: 2012-05-10
Hi!

I have a page in my website that requires Cookies, Java Applets (JRE) and JavaScript.

I tried System.Web.HttpBrowserCapabilities browser = Request.Browser; and only if all requeriments are fulfilled, the browser redirects to the page. But even with Java disabled, the page is redirected.

            System.Web.HttpBrowserCapabilities browser = Request.Browser;

            if (browser.JavaApplets)
            {

                if (browser.Cookies)
                {

                    if (browser.EcmaScriptVersion.Major > 1)
                    {
                        Response.Redirect("~/mypage.aspx");
                    }
                    else
                    {
                        Label1.Text += "No JavaScript.";
                    }
                }
                else
                {
                    Label1.Text += "No Cookies.";
                }
            }
            else
            {
                Label1.Text += "No Java.";
            }

Open in new window


How can I check all these requirements?

Thanks in advance!
0
Comment
Question by:calypsoworld
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +1
9 Comments
 

Expert Comment

by:fsouzabrasilrj
ID: 33496197
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 33497051
Use Java to do the redirect leaving a message if it doesn't work.
0
 
LVL 28

Expert Comment

by:sybe
ID: 33499164
That is because your code only checks for what a browser *could* support, based on the browser application name. Your code does not test for what the browser actually supports.

If you want to check for javascript, then you use some javascript to see if that works.
If you want to check if java (applets) will works, then you need to have a java-applet in the page and see if that works.
etc.

In other words: check for what the browser actually does, and not what it could theoretically do.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:calypsoworld
ID: 33543650
> sybe

Ok, but how to do these tests?
Thanks!
0
 
LVL 28

Accepted Solution

by:
sybe earned 250 total points
ID: 33548829
this is sort of the simplest:

<script>document.write('your browser supports javascript');</script>
<noscript>your browser does <b>not</b> support javascript</noscript>

for redirecting you could use:
<script>document.location='javascriptsupported.aspx';</script>

With support for java-applets you can do the same: write an applet that will redirect the browser. If the browser is redirected, java-applets are working, if not, then the browser does not support java-applets.

0
 

Author Comment

by:calypsoworld
ID: 33549134
> sybe

Thank you very much!

What about the cookies verification? Is it possible to check if cookies are enabled on client's browser?
In my solution, I should verify all three capabilities (javascript, applets e cookies).
May I group these validations in one single page? (Like cascate ifs - all conditions passed: okpage.aspx - at least one condition failed: errorpage.aspx)

Thank you!
0
 

Author Comment

by:calypsoworld
ID: 33554874
Help, please.
0
 
LVL 83

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 250 total points
ID: 33555515
Cookies are set and get only on the page request.  If you set a cookie on this page request, you have to wait until the next page request to check it or use javascript/AJAX to send the info back to your server page.

You can check them all on one page.  Set a cookie on the initial page request.  Use the javascript and noscript tags together.  The noscript section puts up a message that users see if the javascript is not enabled.  If the javascript runs then you could use the javascript to check the cookie and put up a message about the Java Applet. Then use the javascript to load the Java Applet.  I think.  The last stage, the Java Applet can then report back to you and do the redirect to the next page.
0
 

Author Closing Comment

by:calypsoworld
ID: 33667666
Thank you!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article discusses how to create an extensible mechanism for linked drop downs.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question