Я пытаюсь сделать форму входа в систему, используя html, css и javascript, и она работает правильно. Но проблема в том, что он не показывал мой html-контент, и он показывает только имя пользователя на другой странице. Кто-нибудь может мне помочь, пожалуйста! Я хочу, чтобы на странице target.html был показан мой html-контент, а также имя пользователя.Как показать содержимое html с помощью onload javascript?
index.html
<html>
<head>
<title>Login page</title>
</head>
<body>
<h1 style="font-family:Comic Sans Ms;text-align="center";font-size:20pt;
color:#00FF00;>
Simple Login Page
</h1>
<form name="myform">
Username<input type="text" name="userid" id="userid"/>
Password<input type="password" name="pswrd"/>
<input type="button" onclick="check(this.form)" value="Login"/>
<input type="reset" value="Reset"/>
</form>
<script language="javascript">
function check(form)
{
if(form.userid.value && form.pswrd.value)
{
window.location="target.html"
alert("Welcome to this page")
var userid = document.getElementById("userid").value;
localStorage.setItem("userid", userid);
}
else
{
alert("Error Password or Username")
}
}
</script>
</body>
</html>
target.html
<html>
<head>
<title>Login page</title>
<style>
h1.text{
color: red;
}
</style>
<script>
function init(){
var userid = localStorage.getItem("userid");
document.write("Welcome "+userid);
}
window.onload=init;
</script>
<body>
<h1 class="text">Simple Login Page</h1>
<a href="confirm.html">Confirm.html</a>
</body>
</html>
Не используйте 'document.write'. – SLaks
У вас есть несколько проблем. Хуже всего document.write. Другой заключается в том, что вы не можете ничего сделать на текущей странице после изменения местоположения – mplungjan