skip to Main Content

I am trying to put a link in JS, but I want to make it a file, but its only allowing a https. How do I make it a file?

JS:

function login() {
    var username = document.getElementById("username").value;
    var password = document.getElementById("password").value;
  
    
    if (username == "admin" && password == "admin") {
        window.location = "";
    } else {
      window.location = ""
    }
}

2

Answers


  1. By providing the path to the local file within the window.location assignment.

    Here is your updated JS code:

    function login() {
        var username = document.getElementById("username").value;
        var password = document.getElementById("password").value;
    
        if (username == "admin" && password == "admin") {
            window.location = "path/to/your/file.html";
        } else {
            window.location = "path/to/another/file.html"; 
        }
    }
    
    Login or Signup to reply.
  2.  function login() {
        var username = document.getElementById("username").value;
        var password = document.getElementById("password").value;
    
        if (username == "admin" && password == "admin") {
            window.location.pathname = "path/to/your/file.html";
        } else {
            window.location.pathname = "path/to/another/file.html"; 
        }
    }
    

    Or you can refer to this site : https://www.w3schools.com/js/js_window_location.asp

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search