我在我的網頁上有簡單的登錄表單。它使用JavaScript來登錄用戶,工作正常。 問題在於,用戶將着陸頁網址直接輸入到地址欄中,他直接可以訪問該頁面而無需登錄。如果他沒有登錄,我想將他重定向到登錄頁面。下面的 是loding和目標頁面的鏈接。重定向html頁面如果沒有登錄
登錄:http://samdesign.comli.com/protected/index.html
目標:http://samdesign.comli.com/protected/user-soft.html
,這裏是使用腳本低於..
<form>
<table align=center>
<tr>
<td>Username:</td>
<td><input type="text" name="username" style="background:#bfbfbf;color:#212121;border-color:#212121;" onFocus="this.style.background = '#ffffff';" onBlur="this.style.background = '#bfbfbf';"></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="password" style="background:#bfbfbf;color:#212121;border-color:#212121;" onFocus="this.style.background = '#ffffff';" onBlur="this.style.background = '#bfbfbf';"></td>
</tr>
<tr>
<td></td>
<td align=right><input type="button" value="Login" onClick="Login(this.form);" style="background:#bfbfbf;color:#000000;border-color:#212121;" onMouseOver="this.style.color = '#404040';" onMouseOut="this.style.color = '#000000';" onFocusr="this.style.color = '#404040';" onBlur="this.style.color = '#000000';"></td>
</tr>
</table>
</form>
腳本是這樣的
function Login(form) {
username = new Array("numair","sam","u3","u4","u5","u6","u7","u8","u9","u10","temporary");
password = new Array("nk1994","sf1993","p3","p4","p5","p6","p7","p8","p9","p10","user");
page = "/protected/user-soft.html";
if (form.username.value == username[0] && form.password.value == password[0] || form.username.value == username[1] && form.password.value == password[1] || form.username.value == username[2] && form.password.value == password[2] || form.username.value == username[3] && form.password.value == password[3] || form.username.value == username[4] && form.password.value == password[4] || form.username.value == username[5] && form.password.value == password[5] || form.username.value == username[6] && form.password.value == password[6] || form.username.value == username[7] && form.password.value == password[7] || form.username.value == username[8] && form.password.value == password[8] || form.username.value == username[9] && form.password.value == password[9] || form.username.value == username[10] && form.password.value == password[10]) {
self.location.href = page;
}
else {
alert("Either the username or password you entered is incorrect.\nPlease try again.");
form.username.focus();
}
return true;
}
任何一個可以幫助有exapmle?
? – sam
它的工作.... :) – sam
歡呼的人!下一個代碼的最佳運氣... – Ashish