编程语言
首页 > 编程语言> > javascript – Window.location不工作我已经尝试了eveything

javascript – Window.location不工作我已经尝试了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?";
    }

}

window.location无法正常工作.页面名称是正确的,当信息正确但程序将加载到新页面时,程序会给出window.alert.任何人都知道它为什么不起作用?请帮忙!我已经好几个小时了.

解决方法:

您从本地文件系统中打开了html.虽然它似乎乍一看,但出于安全原因,许多功能都被禁用.其中一个可能是页面重定向.

我建议您抓住一些开发网络服务器,并通过它来提供您的文件.请参阅nodejs的express或connect,或python的以下内容:

>导航到您的webapp的根目录
>为python3运行python -m http.server,或者为python2运行python -m SimpleHTTPServer
>在浏览器中打开http:// localhost:8000

大多数JavaScript和HTML IDE都有一些内置的服务功能.

标签:window-location,javascript
来源: https://codeday.me/bug/20190829/1760793.html