Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

173
Views
after use html and javascript to make login page, want to prevent others go to linked page directly

I have a html login page and use javascript to hide the user name and password:

Javascript:

function myFunction(){
var user = document.getElementById("username").value;
 var pass = document.getElementById("pass").value;

if(user == "user1" && pass == "zzxx"){
          window.location.href="about.html"}

 else if(user == "user2" && pass == "xxzz"){
        window.location.href="about2.html"}
 
   
else if(user == "user3" && pass == "ooppp"){
        window.location.href="about3.html"  
   
     } else{
  alert("Incorrect username or password");
  }

HTML:

    html lang="en" dir="ltr">
 <head>

  <meta charset="utf-8">
 <title>Login</title>
 <meta name="viewport" content="width=device-width, initial-scale=1">
 <link rel="stylesheet" href="css/bootstrap.min.css">
 <script src="js/jquery.min.js"></script>
 <script src="js/bootstrap.min.js"></script>
 <link rel="stylesheet" href="css/style.css">
   <script src="js/jquery-1.8.2.js"></script>
  <script type="text/javascript" src="js/invisible_debut.js" ></script>

  </head>
  <body>

   <div class="loginBox">
   
    <h1>Login</h1>
    <div class="textbox">
        <i class="fas fa-user"></i>
        <input  name="username" id="username" type="text"placeholder="Username">
    </div>

    <div class="textbox">
        <i class="fas fa-lock"></i>
        <input name="pass" id="pass" type="password"placeholder="Password">
    </div>

    <button  value="Submit" class="btn btn-success" 
    onclick="myFunction()">Submit</button>
        </form>
    </div>
    </body>

 <div class="bg"></div>
   </html>

I want to prevent the user to go to about.html by directly typing ..../about.html I only want people to login through user name and password. How can I do that? Many Thanks!

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

you can use document.referrer to check if its your website or not

about 4 years ago · Juan Pablo Isaza Report

0

You will need to store some information on

localStorage

to make sure that this user already visited and logged in to your website. When users will try to go directly to the about page without logging in - you can redirect them to the login page.

about 4 years ago · Juan Pablo Isaza Report

0

Use session-storage or local-storage to store the value of the user, then check that value in about page, if not exists then redirect the user back to the index page.

function myFunction() {

  var user = document.getElementById("username").value;
  var pass = document.getElementById("pass").value;

  if(user == "user1" && pass == "zzxx") {
    window.sessionStorage.setItem("user", "user1"); 
    window.location.href="about.html"
  } else if(user == "user2" && pass == "xxzz") {
    window.sessionStorage.setItem("user", "user2");
    window.location.href="about2.html"
  } else if(user == "user3" && pass == "ooppp") {
    window.sessionStorage.setItem("user", "user3");
    window.location.href="about3.html"
  } else {
    alert("Incorrect username or password");
  }

Use the above session-storage-item in about page

window.onload = function() {
  if (window.sessionStorage.getItem("user")) {
    var usr = window.sessionStorage.getItem("user");
    if(user != "user1") {
      window.location.replace("index.html");
    }
  } else {
    window.location.replace("index.html");
  }
}

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!