Prevent use of website if javascript is not enabled or present

I need to prevent my employees from using our Intranet if they don't have javascript enabled or present on their home machine.  Is there a way to do this with javascript ?  Perhaps test for java and if not enabled, redirect them to an alternate page ?
Mark DrelingerMISAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

prunckleCommented:
Dear drelinger,

Your best bet is to use the <noscript></noscript> tag within the head section of the document.

Please let me knwo if you would like me to provide particular examples.  You might be able to stop the user from accessing the page if you are using an active platform like PHP or ASP....

Please let me know
<head>
 
<noscript>
You must have JavaScript enabled to use this site!
</noscript>
 
</head>
 
<body>
your HTML here
</body>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Michel PlungjanIT ExpertCommented:
Noscript is not a valid tag in the head I believe.. HTML certainly does not belong there...

Welcome to the site. Click below to continue

<script>
document.write('<a href="jsenabled_site.html">ENTER</a>')
</script>
<noscript>
<a href="whyYouNeedToEnableJs.html">Why you need to enable javascript</a>
</noscript>
0
prunckleCommented:
mplungjan,

Good point...the HTML 4.01 specification does not restrict <noscript> to any particular containder that I've been able to find.  From my past experience, I've had a lot of users complain about "Enter" pages.  So in those cases I write my indexes with <noscript> in the <head> container - with the HTML for the display within <noscript></noscript> tags.  Ugly, but effective.  It has increased user traffic and forced users to turn on JavaScript to view the site.

But I bow to your superior knowledge!  (how you're a Ben Stein fan!)
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Mark DrelingerMISAuthor Commented:
thank you.  It is an .asp page (sorry I didn't post that earlier).  Would you suggest putting this script into the login page, or create a pre-login page ?
0
prunckleCommented:
drelinger,

Well, if you have a login page, then as mplungjan noted above, you can use document.write to generate your HTML that only javascript enabled browsers will see and use <noscript></noscript> to display infrmation that JavaScript is needed to enter the site.  This can be done from the main login page.
0
Mark DrelingerMISAuthor Commented:
ok, I'm close.  I added the the <noscript> tags to the header.  Now I see the message correctly when the user doesn't have javascript enabled, however the rest of the page continues to load.  Is there a way that I can I stop the rest of the page from loading ?
0
prunckleCommented:
You can stop the rest of the page from loading by generating the HTML through JavaScript's document.write("") function.  it becomes a bit more verbose, but if the person doesn't have javascript enabled, there's no way for them to access the rest of the page.

If you want to send your code, I can give it a kick for you.
0
Mark DrelingerMISAuthor Commented:
Thanks for your help.  I'm confused on where to put the document.write.  I truly appreciate you taking a peak .

<%@LANGUAGE="VBSCRIPT"%>
<%
If cstr(Request.Form("username"))<>"" Then
Session("username") = Request.Form("username")
  If Request.form("checkbox") ="1" Then
     Response.Cookies("UsernameCookie") = Request.Form("username")
     Response.Cookies("PasswordCookie") = Request.Form("Password")
     Response.Cookies("RememberMeCookie") = "1"
     Response.Cookies("UsernameCookie").expires = Date + 30
     Response.Cookies("PasswordCookie").expires = Date + 30
     Response.Cookies("RememberMeCookie").expires = Date + 30
  Else
     Response.Cookies("RememberMeCookie") = "" 
     Response.Cookies("UsernameCookie") = "" 
     Response.Cookies("PasswordCookie") = ""     
  End If
End If
%>
<!--#include file="../Connections/MDIS.asp" -->
<%
set rsLogin = Server.CreateObject("ADODB.Recordset")
rsLogin.ActiveConnection = MM_MDIS_STRING
rsLogin.Source = "SELECT * FROM LoginData"
rsLogin.CursorType = 0
rsLogin.CursorLocation = 2
rsLogin.LockType = 3
rsLogin.Open()
rsLogin_numRows = 0
%>
<%
' *** Validate request to log in to this site.
MM_LoginAction = Request.ServerVariables("URL")
If Request.QueryString<>"" Then MM_LoginAction = MM_LoginAction + "?" + Server.HTMLEncode(Request.QueryString)
MM_valUsername=CStr(Request.Form("username"))
If MM_valUsername <> "" Then
  MM_fldUserAuthorization="AccessGroup"
  MM_redirectLoginSuccess="https://www.TeamSchmidt.com"
  MM_redirectLoginFailed="FailedLogin.asp"
  MM_flag="ADODB.Recordset"
  set MM_rsUser = Server.CreateObject(MM_flag)
  MM_rsUser.ActiveConnection = MM_MDIS_STRING
  MM_rsUser.Source = "SELECT UserName, Password"
  If MM_fldUserAuthorization <> "" Then MM_rsUser.Source = MM_rsUser.Source & "," & MM_fldUserAuthorization
  MM_rsUser.Source = MM_rsUser.Source & " FROM LoginData WHERE UserName='" & Replace(MM_valUsername,"'","''") &"' AND Password='" & Replace(Request.Form("Password"),"'","''") & "'"
  MM_rsUser.CursorType = 0
  MM_rsUser.CursorLocation = 2
  MM_rsUser.LockType = 3
  MM_rsUser.Open
  If Not MM_rsUser.EOF Or Not MM_rsUser.BOF Then
    ' username and password match - this is a valid user
    Session("MM_Username") = MM_valUsername
    If (MM_fldUserAuthorization <> "") Then
      Session("MM_UserAuthorization") = CStr(MM_rsUser.Fields.Item(MM_fldUserAuthorization).Value)
    Else
      Session("MM_UserAuthorization") = ""
    End If
    if CStr(Request.QueryString("accessdenied")) <> "" And true Then
      MM_redirectLoginSuccess = Request.QueryString("accessdenied")
    End If
    MM_rsUser.Close
    Response.Redirect(MM_redirectLoginSuccess)
  End If
  MM_rsUser.Close
  Response.Redirect(MM_redirectLoginFailed)
End If
%>
<html>
<head>
<title>Schmidt Web Applications</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<noscript>
You must have JavaScript enabled to use this site!
</noscript>

<!-- ##BEGIN SCROLLING -->
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--
// Scrolling status Bar text Script
// Being of Scrolling text in the Status bar
var speed = 50 //decrease value to increase speed (must be positive)
var pause = 2500 //increase value to increase pause
var timerID = null
var bannerRunning = false
var ar = new Array()
ar[0] = "Welcome to TeamSchmidt.com"
ar[1] = "                   "
ar[2] = "Please forward any questions to the developer, Mark Drelinger, at 508-987-8786"
ar[3] = ""
ar[4] = ""
var currentMessage = 0
var offset = 0
function stopBanner() {
      if (bannerRunning)
            clearTimeout(timerID)
            bannerRunning = false
            }
function startBanner() {
            stopBanner()
            showBanner()
}
function showBanner() {
            var text = ar[currentMessage]
            if (offset < text.length) {
                  if (text.charAt(offset) == " ")
                  offset++
                  var partialMessage = text.substring(0, offset + 1)
                  window.status = partialMessage
                  offset++
                  timerID = setTimeout("showBanner()", speed)
                  bannerRunning = true
                        } else {
                  offset = 0
                  currentMessage++
                        if (currentMessage == ar.length)
                              currentMessage = 0
                              timerID = setTimeout("showBanner()", pause)
                              bannerRunning = true
                              }
                                          }
// -->
</SCRIPT>
<!-- ##END SCROLLING -->
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--
function Logon_onload() {
    window.document.forms[0].elements[1].focus()
}
<!--
//this is to start the Scrolling Status Bar
startBanner();
// -->


function TM_UpperCase(strInput,words){//1.1
    var theString = strInput.value;
    var strOutput = "";// Our temporary string used to build the function's output
    var sp = " ";
    var small = false;
    var smallWords = words.split(",") //words that shouldn't be  capitalized
    theString = theString.replace(/(\s*)([^\s])/,"$2")//remove leading spaces
    theString = theString.toLowerCase();  
    var inputArray = theString.split(sp);
    strOutput = inputArray[0].slice(0,1).toUpperCase()+inputArray[0].slice(1);
    for (i = 1; i < inputArray.length; i++){
        small=false;
        for (ii=0;ii<smallWords.length;ii++){
           if(inputArray[i] == smallWords[ii]) small = true;
           }
        if(!small) inputArray[i] = inputArray[i].slice(0,1).toUpperCase()+inputArray[i].slice(1);
        strOutput = strOutput + sp + inputArray[i];  
        }
    strInput.value = strOutput;
}

function MM_popupMsg(msg) { //v1.0
  alert(msg);
}
//-->
</SCRIPT>
<STYLE>
.mystyle1 { BACKGROUND:FFFECC;COLOR:CC5700;FONT-FAMILY:"Times New Roman";FONT-SIZE:12;}
a:link {
      text-decoration: none;
}
a:visited {
      text-decoration: none;
      color: 004000;
}
a:hover {
      text-decoration: underline;
      color: 99000;
}
a:active {
      text-decoration: none;
}
body {
      margin-left: 5px;
      margin-top: 5px;
}
</STYLE>
</head>
<body bgcolor="#FFFFFF" text="#000000" onload="return Logon_onload()">
<table width="60%"  border="1" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td> <form name="Login" method="POST" action="<%=MM_LoginAction%>">
      <p>&nbsp;</p>
      <table width="100%" border="0">
        <tr>
          <td colspan="3"><div align="center"><font size="2">Schmidt Equipment, Inc.<br>
                Sign In &amp; Authorization <br>
  --------------------------------------------------------------------------------</font></div></td>
        </tr>
        <tr>
          <td colspan="3"><div align="center"><a href="../menu.asp" target="_parent"><font size="2">Woops ? Did you get here by Mistake ? <br>
  Click here to return home</font></a></div></td>
          </tr>
        <tr>
          <td colspan="3">&nbsp;</td>
          </tr>
        <tr>
          <td width="40%"><div align="right"><font size="2">User Name:</font></div></td>
          <td width="30%">
            <p><font size="2">
              <input value="<%= Request.Cookies("UsernameCookie") %>" name="username" type="text" id="username2" onBlur="TM_UpperCase(this,'')">
          </font></p></td>
          <td width="30%">&nbsp;</td>
        </tr>
        <tr>
          <td width="40%"><div align="right"><font size="2">Password: </font></div></td>
          <td width="30%"> <font size="2">
            <input name="Password" type="password">
          </font></td>
          <td width="30%"> <font size="2">
            <input type="submit" name="Submit" value="Login">
          </font></td>
        </tr>
        <tr>
          <td>
            <div align="right">
              <input <%If (Request.Cookies("RememberMeCookie") = "1") Then Response.Write("CHECKED") : Response.Write("")%> type="checkbox" name="checkbox" value="1">
            </div></td>
          <td colspan="2">            <font size="2">Rememer User Name for 30 Days? <a href="javascript:;" onClick="MM_popupMsg('By checking this box, your Username will be stored on this computer for 30 days.')"><img src="Images/question.gif" width="18" height="18" border="0"></a></font></td>
          </tr>
        <tr>
          <td height="17" colspan="3"><div align="center"><font size="2">--------------------------------------------------------------------------------<a href="PasswordReminder1.asp"><br>
            Forgot your password?</a></font></div></td>
          </tr>
      </table>
      </form></td>
  </tr>
</table>
 <p>&nbsp;</p>
</body>
</html>
<%
rsLogin.Close()
%>
0
Michel PlungjanIT ExpertCommented:
That was my next question too to prunckle - how putting the noscript in the head would make the non-noscript not show.....

You could do this



<html>
<head>
<script>
location.replace('jsenabled_site.html')
</script>
</head>
<body>
<noscript>
<a href="whyYouNeedToEnableJs.html">Why you need to enable javascript</a>
</noscript>
</body>
</html>
 
OR
 
<html>
<head>
</head>
<body style="margin:0">
<script>
document.write('<iframe width="100%" height="100%" src="page.asp?jsenabled=true"></iframe>')
</script>
<noscript>
<iframe width="100%" height="100%" src="page.asp?jsenabled=false"></iframe>
</noscript>
</body>
</html>
 
 
OR
 
 
 
<html>
<head>
</head>
<body style="margin:0" onLoad="window.frames[0].location.replace('page.asp?jsenabled=true')">
<iframe width="100%" height="100%" src="page.asp?jsenabled=false"></iframe>
</body>
</html>

Open in new window

0
Michel PlungjanIT ExpertCommented:
I am a Ben Stein fan ???
0
prunckleCommented:
mplungjan,

You beat me to the puch on that last suggestion!

And yes the document.write() function was my choice using an iframe.

Ideally you have two options...the brute force method:
---within the body tags---
 
<script language="javascript" type="text/javascript">
document.write("<table width=\"60%\"  border=\"1\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">");
</script>

Open in new window

0
Michel PlungjanIT ExpertCommented:
@prunckle: Is it not simpler to wrap the html in single quotes:
document.write('<table width="60%"  border="1" align="center" cellpadding="0" cellspacing="0">......</table>');

and how am I a Ben Stein fan?
0
prunckleCommented:
with which you would surround all the HTML tags in document.write(""); and using "\" to escape the additional "'s.

But the best method is to call the existing login page via:
<body>
<script language="javascript" type="text/javascript">
document.write("<iframe src=\"loginpage.htm\" width=\"100%\" height=\"100%\" scrolling=\"auto"\ name=\"mainFrame\">");
</script>
</body>

Open in new window

0
prunckleCommented:
mplungjan,

I always had problems with JavaScript choking on single quotes on some server platforms - since I usually write on academic servers that lack a lot of functionality....

As for the Ben Stein thing...remember the show "Ben Stein's Money" on comedy central?  Whenever Ben lost, he always said, "I bow to your superior knowledge.  I hate you.  Take my money and get out of here!"  :)  Sorry....my humor is somewhat obscure!

But thatks for the suggestions all the way around.  I'm learning here too!
0
Michel PlungjanIT ExpertCommented:
thanks - no, I never watch comedy central - we just got it here in Holland but I am too busy on the web :|
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.