使用网页登录到apache服务器



我这里有这个代码:

<html>
<body style="color:white;background-color:#222222">
<center>
<br>
<input type="text" id="username"> Username</input>
<br>
<input type="text" id="password"> Password</input>
<br><br>
<button onclick="test()">Submit</button>
<p id="url"/>
<script type="text/javascript">
function test(){
var userInput = document.getElementById("username").value;
var userPass = document.getElementById("password").value;
document.getElementById("url").innerHTML = encodeURI('http://'+userInput+':'+userPass+'@'+window.location.hostname+':81/Home/');
}
</script>
</center>
</body>
</html>

它输出一个工作的url。当我指定正确的密码时,它会将我登录到受密码保护的文件夹中。唯一的问题是,我希望"提交"按钮自动将我重定向到指定的页面,而不是显示url。

我什么都试过了。请帮忙。谢谢

请检查此项:

function test(){
var userInput = document.getElementById("username").value;
var userPass = document.getElementById("password").value;
location.href = encodeURI('http://'+userInput+':'+userPass+'@'+window.location.hostname+':81/Home/');
}

而不是

document.getElementById("url").innerHTML = etc 

使其成为

window.location.href = etc 

最新更新