Solved

Checking browser capabilities

Posted on 2010-08-22
9
623 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
  • 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
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…

776 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