 |
 | Really helpful, but one suggestion PGumbo | 14:38 27 Feb '09 |
|
 |
This is really helpful, thank you. The one thing I noticed is that this will go into an infinite loop if javascript is enabled but cookies are disabled, so you may want to check for the querystring as well as the session variable, like:
if (Session["JSChecked"] == null && Request.QueryString["JScript"] == null)
|
|
|
|
 |
 | Why Response.Write method fails in FireFox JamieS | 9:44 25 Feb '09 |
|
 |
Response.Write(@"<script language='javascript' type='text/jscript'>window.location='default.aspx?JScript=1'; </script>");
Unfortunately, this code does not work if the browser is FireFox. However using the command ----------------------------------------------------------------------------------------------- The reason FireFox fails to run this code is because it does not use understand 'text/jscript'. Replace the type with 'text/javascript' and both FireFox and IE execute the code. (I have not tested other browsers).
Response.Write(@"<script language='javascript' type='text/javascript'>window.location='default.aspx?JScript=1'; </script>");
|
|
|
|
 |
 | Alternative to check javascript support without roundtrip [modified] Red Feet | 23:29 25 Feb '08 |
|
 |
Good idea to make programmers aware of the fact that JavaScript could be disabled or not supported for other reasons (think of WebCrawlers and SearchBots that do consume HTML, but don't support JavaScript).
An alternative way to use your code for checking if the browser supports JavaScript, without the page reloading itself, is to make a link to your detection page like this:
<a href="jsdetect.aspx?JScript=0" onclick="this.href='jsdetect.aspx?JScript=1'" >Next page</a>
You can leave the Session variable out (which consumes a small amount of server RAM per visitor) and check whether the JScript parameter is either 0 (javascriptEnabled=false) or 1 (javascriptEnabled=true)
================= Red Feet - internet oplossingen - =================
<div class="ForumMod">modified on Tuesday, February 26, 2008 4:23 PM</div>
|
|
|
|
 |
|
 |
That is an excellent idea. Particularly if I put it on the script for the Login button on the previous web page.
|
|
|
|
 |
 | Why not Request.Browser.JavaScript ?? Dileep.M | 19:34 25 Feb '08 |
|
 |
These are other bst alternatives..(I think) 1.Request.Browser.JavaScript returns boolean. 2.Inbuild <noscript> html tag.
Dileep.M </noscript>
|
|
|
|
 |
|
 |
I think because this show if the browser "supports" JavaScript or not, it doesn't show if the user has disabled JavaScript.
Make it simple, as simple as possible, but not simpler.
|
|
|
|
 |
 | Re: Why not Request.Browser.JavaScript ?? Dileep.M | 23:45 25 Feb '08 |
|
 |
Yes,
http://msdn2.microsoft.com/en-us/library/aa332781(VS.71,printer).aspx
Dileep.M
|
|
|
|
 |
|
 |
Yes, that is exactly why. The same holds true for Request.Browser.EcmaScriptVersion. It tells what version of JavaScript is supported, but not if it is enabled currently.
|
|
|
|
 |
 | thanks binabic | 7:47 23 Feb '08 |
|
 |
Simple but useful in every application. Must have. Thx!
|
|
|
|
 |
 | Here is another way! azamsharp | 6:36 23 Feb '08 |
|
|
 |
|
 |
Hello Azam,
The article is about detecting JavaScript support in ASPX (Server Side) and having a boolean containing the result of the check: true/false So you can do something with this information programmatically.
Your solution is (as you mention in the title) in JavaScript (Client Side) and doesn't give a true/false answer on the server side.
But for displaying if JavaScript is supported/enabled to the visitor, your script is perfect since it is independent of the platform and doesn't need a roundtrip.
================= Red Feet - internet oplossingen - =================
|
|
|
|
 |
 | Thanks Jeffrey Walton | 15:43 22 Feb '08 |
|
 |
Hi Shawn,
Thanks for the article. I wish all web developers would use it. I'm a System Administrator. I've hardened browsers at many sites (i.e., disable JavaScript, ActiveX, etc in the Internet Zone).
I wish more developers understood security, and programmed accordingly.
Jeff
|
|
|
|
 |