[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Check if javascript is enabled (asp.net 2 and atlas)

Posted on 2006-11-07
14
Medium Priority
?
351 Views
Last Modified: 2008-01-09
I have a site where I want to give the user a warning when they are entering without javascript enabled so:
How do I check if javascript is enabled or not (Provide code example) using asp.net 2 (and atlas).

0
Comment
Question by:dogbrain
[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
  • 8
  • 6
14 Comments
 
LVL 3

Author Comment

by:dogbrain
ID: 17889390
btw it must work for all major browsers supported by atlas
0
 
LVL 11

Expert Comment

by:ethoths
ID: 17889471
On you default page put this...

<script language="javascript">
<!--
    window.location.href="home.aspx"
// -->
</script>

<body>
    Sorry your browser does not support Javascript
</body>
0
 
LVL 11

Expert Comment

by:ethoths
ID: 17889500
Sorry, a bit more explanation.

Don't beleive waht people tell you about using the Brower object to detect the client capabilities - It does not work. It only tells you what we think the browser can do and does not know if a feature has been turned off. The only way to check for sure is to test it like in my previous mail. If you have JS and it's enables you get directed to the home page, otherwise you see a message. Sorry it not atlas - I'm not all that clued up on atlas yet.

0
Technology Partners: 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!

 
LVL 3

Author Comment

by:dogbrain
ID: 17889562
Thanks for the info.

This doesnt detect javascript.. it opens another page if there is javascript.... I want to use the detection on more places so therefore i need a check if the javascript is enabled or not.
0
 
LVL 11

Accepted Solution

by:
ethoths earned 375 total points
ID: 17889741
What it does is to use a javascript enabled browser to direct the user to your site. If the user does not have JS enabled then they stay where they are and don't enter the site. You can use the fact that they ended up on your home page as an indication that they have JS.

If you're worried that somebody might type the url in directly you can try authenticating the redirect by..

1) create a random number (or use a guid)
2) store this in session stare and and append it to the window.location.href querystring.
3) on the home page make sure that the two are the same.
4) Strore the fact that the user has JS in sessio state
5) In all your pages (prehaps your base page) put some code to see if this is set and iff not direct your user to the default page.

That's a pretty comprehensive and fool proof explanation and is the one that I use to detect all sorts of things like javascript, cookies and window media player.

0
 
LVL 3

Author Comment

by:dogbrain
ID: 17889920
Sorry still need a function so that I can chenge some of the behavior in my atlas site if there is no javascript
0
 
LVL 11

Expert Comment

by:ethoths
ID: 17890060
Maybe you should reword your question then because my solution does...

 "...give the user a warning when they are entering without javascript enabled..."

Actually it goes further as it detects this on every page request, not just entering.

However, if you want a function then why not rather then doing a redirect in the base page, render a JS variable set to the session var...

dim litJS as new literal
litJS.text="<script language='javascript'>var boolHasJS=" & session("boolHasJS") & ";</script>"
me.control.add(litJS)

you can then use boolHasJS in your subsequent javascript like...

if(boolHasJS){}

0
 
LVL 3

Author Comment

by:dogbrain
ID: 17896368
Sorry I still need a function that detects if javascript is enabled or not. (Cant use the redirect for security reasons.. need to do it at my login page)... So ignore my questions first line.
0
 
LVL 3

Author Comment

by:dogbrain
ID: 17896373
And if  javascript is not enabled... then I cant use it in the javascript :)... (eg i need it in my .net code)
0
 
LVL 11

Expert Comment

by:ethoths
ID: 17898488
Are you a moron? session("boolHasJS") is .net code!

Sorry but this is just too painful for 125 points.
0
 
LVL 3

Author Comment

by:dogbrain
ID: 17905277
Hmm nope you are... you assume that I need to check in a javascript if javascript is enabled
0
 
LVL 3

Author Comment

by:dogbrain
ID: 17963801
Solved it by using
<div id="noJavaScript" style="display:block">###Login code  with no javascript enabled###</div>
<div id="javaScript" style="display:none">###Login code withjavascript enabled###</div>
<script type="text/javascript">
        document.getElementById("noJavaScript").style.display="none";
        document.getElementById("javaScript").style.display = "block";        
</script>

On the only page that it would work.. at my forms login page... Unfortunatly its not a perfect solution since setFocus etc wont work properly..
And then setting a Session variable depending on what login form is used
0
 
LVL 3

Author Comment

by:dogbrain
ID: 17963817
Sorry I didnt explain my problem properly.. points awarded :) and the solution I used was another
0
 
LVL 11

Expert Comment

by:ethoths
ID: 17963938
Oh so you decided to use some javascript to detect if javascript was enabled afterall. The only significant difference between your code and my code is that my code used javascript to redirect to another page where as yours used javascriupt to show and hide panels. Essentially they are the same thing.

My assumption was that you did not want users to enter the site if they did not have javascript. This is how framed site work. If tyou had said that I would have recommended this...

Login code Goes here

<script type="text/javascript">
    document.getElementById("hasJS").value="yes"
</script>

<input type=hidden id="hasJS" value="no" />

Then when ths user submits the form the value of hasJS would indicate whether JS was enabled. Bonus - setFocus will work and you have cleaner code.

Thanks for the points though.

0

Featured Post

Technology Partners: 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!

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

656 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