Request.Browser.JavaScript only indicates whether the browser handles the JavaScript or not. You can turn off the JavaScript and it will still say "true". Here is a simple way to test if the JavaScript is enabled or not.
You print a message on the page saying "If you see the message below then the JavaScript is enabled". This means if the message is not displayed then the JavaScript is disabled.
Although I’ve never done this, I will have to in the near future so I’ve been watching the thread.
It seems to me that a good way to do this is to break the page into two panels <divs>, the first visible (‘display: block’ – the default) with a message saying ‘Javascript is disabled, please enable it’, and the second invisible (display: none;). On page
load a Javascript function will hide the first panel and show the second.
If there’s no Javascript, the first panel will show. It will not redirect them of course, but the required content can be shown in the first <div> (one less trip to the server).
JRICE
Contributor
2180 Points
672 Posts
Check if Javascript is disabled
Sep 29, 2007 04:39 PM|LINK
I want to redirect mu users to a Specifc Page, If javascript was disabled??
Im using Asp.net 2.0, Ajax Enabled, Internet explorer
------------------------------------------------------
I tried
if (!Request.Browser.JavaScript)
{
Response.Redirect("JavascriptPage.aspx");
}
Request.Browser.JavaScript is obselete
------------------------------------------------------
I also tried
adding to my master page
<noscript>
<META HTTP-EQUIV=Refresh CONTENT="1;URL=http://localhost:1550/Testing/Default.aspx">
</noscript>
I failed when i set Allow MetaData Refresh to Disabled in my browser?
-------------------------------------------------------
Any Ideas?????????????????????????
HosamKamel
Star
9551 Points
1391 Posts
Re: Check if Javascript is disabled
Sep 29, 2007 08:19 PM|LINK
Check this post http://p2p.wrox.com/topic.asp?TOPIC_ID=19217
Remember to click on Mark as answer on the post that helped you
JRICE
Contributor
2180 Points
672 Posts
Re: Check if Javascript is disabled
Sep 29, 2007 10:38 PM|LINK
Thank you for ur reply
but this link didnt solve my problem since i tried both solution mentioned in the given link
Any ideas?
nps
Participant
1774 Points
397 Posts
Re: Check if Javascript is disabled
Sep 30, 2007 07:15 AM|LINK
Hi ,
Try this
if (Request.Browser.JavaScript)
{
Response.Write("Javascript Enabled") ;
}
else
{
Response.Write("Javascript Disabled") ;
}
Software Engineer
azamsharp
All-Star
24614 Points
4612 Posts
Re: Check if Javascript is disabled
Sep 30, 2007 12:46 PM|LINK
Request.Browser.JavaScript only indicates whether the browser handles the JavaScript or not. You can turn off the JavaScript and it will still say "true". Here is a simple way to test if the JavaScript is enabled or not.
You print a message on the page saying "If you see the message below then the JavaScript is enabled". This means if the message is not displayed then the JavaScript is disabled.
<body onload="checkJavaScriptValidity()">
<script language="javascript" type="text/javascript">
function checkJavaScriptValidity()
{
document.getElementById("divDisplay").innerHTML = "If you see this message then your JavaScript is enabled.";
}
</script>
HighOnCoding
bpw
Contributor
2258 Points
490 Posts
Re: Check if Javascript is disabled
Sep 30, 2007 03:06 PM|LINK
Although I’ve never done this, I will have to in the near future so I’ve been watching the thread.
It seems to me that a good way to do this is to break the page into two panels <divs>, the first visible (‘display: block’ – the default) with a message saying ‘Javascript is disabled, please enable it’, and the second invisible (display: none;). On page load a Javascript function will hide the first panel and show the second.
document.getElementById("JsWarning").style.display = "none";
document.getElementById("theContent").style.display = "block";
If there’s no Javascript, the first panel will show. It will not redirect them of course, but the required content can be shown in the first <div> (one less trip to the server).
Will this work, or am I missing something?
bpw
Contributor
2258 Points
490 Posts
Re: Check if Javascript is disabled
Sep 30, 2007 03:50 PM|LINK
Mmm, I guess the Javascript-enabled browser would initially see the warning message?
I wonder why the <noscript> option doesn’t work? This seems to be the most popular option.
<noscript>
<meta http-equiv=”Refresh” content =”0;URL=noscript.aspx” />
</noscript>
I get a warning that it shouldn’t appear in the <head> section, but apparently this is an oversight and can safely be ignored?
azamsharp
All-Star
24614 Points
4612 Posts
Re: Check if Javascript is disabled
Sep 30, 2007 09:55 PM|LINK
You can do something like this:
<div id="jsEnabled" style="visibility:hidden">
JavaScript is enabled
</div>
<div id="jsDisabled">
JavaScript is disabled
</div>
<script language="javascript" type="text/javascript">
function checkJavaScriptValidity()
{
document.getElementById("jsEnabled").style.visibility = 'visible';
document.getElementById("jsDisabled").style.visibility = 'hidden';
}
</script>
;)
HighOnCoding
JRICE
Contributor
2180 Points
672 Posts
Re: Check if Javascript is disabled
Sep 30, 2007 10:29 PM|LINK
I want to redirect user to another page in case of javascript disabled
HosamKamel
Star
9551 Points
1391 Posts
Re: Check if Javascript is disabled
Oct 01, 2007 05:23 AM|LINK
Try to check this article too http://aspadvice.com/blogs/azamsharp/archive/2007/09/30/Check-If-the-JavaScript-is-Enabled-on-the-Client_2700_s-Browser.aspx
Remember to click on Mark as answer on the post that helped you