SpiderMonkey
SpiderMonkey

Reputation: 161

Window.location not working I have tried eveything

/*jslint plusplus: true*/
function signin() {
    'use strict';
    localStorage.setItem("index", 0);
    var get, sn, get1, text, i;
    get = localStorage.getItem("login");
    get1 = JSON.parse(get);
    sn = document.getElementById("studentnumber").value;

    if (sn === get1[0].student) {
        window.alert("Welcome, " + get1[0].fName + get1[0].lName);
        window.location = 'Newsfeed.html';
    } else {
        window.alert = "Sorry Student Number or Password is incorrect! Did up already make an account?";
    }

}

The window.location is not working. The page name is right and the program gives the window.alert when the information is correct but it would load to the new page. Anyone know why it doesn't work? Please help! I've been at it for hours.

Upvotes: 3

Views: 134

Answers (1)

Tamas Hegedus
Tamas Hegedus

Reputation: 29926

You opened your html from the local filesystem. Although it seems to work at first glance, many features are disabled for security reasons. One of them might be page redirect.

I suggest you to grab some development webserver, and serve your files through that. See express or connect for nodejs, or the following for python:

  • Navigate to the root of your webapp
  • Run python -m http.server for python3, or python -m SimpleHTTPServer for python2
  • Open http://localhost:8000 in your browser

Most JavaScript and HTML IDE-s have some builtin serving functionality too.

Upvotes: 5

Related Questions