dogbrain
asked on
Check if javascript is enabled (asp.net 2 and atlas)
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).
How do I check if javascript is enabled or not (Provide code example) using asp.net 2 (and atlas).
On you default page put this...
<script language="javascript">
<!--
window.location.href="home .aspx"
// -->
</script>
<body>
Sorry your browser does not support Javascript
</body>
<script language="javascript">
<!--
window.location.href="home
// -->
</script>
<body>
Sorry your browser does not support Javascript
</body>
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.
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.
ASKER
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Sorry still need a function so that I can chenge some of the behavior in my atlas site if there is no javascript
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){}
"...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){}
ASKER
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.
ASKER
And if javascript is not enabled... then I cant use it in the javascript :)... (eg i need it in my .net code)
Are you a moron? session("boolHasJS") is .net code!
Sorry but this is just too painful for 125 points.
Sorry but this is just too painful for 125 points.
ASKER
Hmm nope you are... you assume that I need to check in a javascript if javascript is enabled
ASKER
Solved it by using
<div id="noJavaScript" style="display:block">###L ogin code with no javascript enabled###</div>
<div id="javaScript" style="display:none">###Lo gin code withjavascript enabled###</div>
<script type="text/javascript">
document.getElementById("n oJavaScrip t").style. display="n one";
document.getElementById("j avaScript" ).style.di splay = "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
<div id="noJavaScript" style="display:block">###L
<div id="javaScript" style="display:none">###Lo
<script type="text/javascript">
document.getElementById("n
document.getElementById("j
</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
ASKER
Sorry I didnt explain my problem properly.. points awarded :) and the solution I used was another
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("h asJS").val ue="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.
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("h
</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.
ASKER