admin管理员组文章数量:1398754
So, I have a button where if the person's username and password is correct, it will notify you, then it will redirect to another page. The first thing works, but it will not redirect you to the page.
Here is the code of the webpage:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
".dtd">
<html xmlns="">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Siur</title>
<script type="text/javascript">
///////////////////////////Login System///////////////////////////
function getCookie(){
var whole, username, password, splitting, actual,user, pass;
whole = document.cookie;
whole = whole.split(';');
username = whole[0];
password = whole[1];
actual = password.split('=');
user = actual[0];
pass = actual[1];
alert(user + password);
}
function setCookie(c_name,value,exdays){
var c_value=value + ";
pass="+document.getElementById('passwordText').value;
document.cookie="=" + value + ";
pass="+document.getElementById('passwordText').value;
alert(document.cookie);
getCookie();
}
function url(url){
document.open(url);
}
function checkCookie(){
var whole, username, password, splitting, actual,user, pass;
whole = document.cookie;
whole = whole.split(';');
username = whole[0];
password = whole[1];
actual = password.split('=');
user = actual[0];
pass = actual[1];
if (document.getElementById('usernameText').value !=null &&
document.getElementById('usernameText').value!="" &&
document.getElementById('passwordText').value == pass) {
alert("Wele again " + user);
document.open('search_webpage.html');
}
else{
alert('Incorrect username or password.');
}
}
//////////////////////////////End of Login system////////////////////////////////////
</script>
</head>
<body>
<table width=100% height=30 background="nav.png" border="0">
<tr>
<td >
<form id="form1" name="form1" method="post" action="">
<label for="searchBox"></label>
IN-DEV 0.1
</form>
</td>
</tr>
</table>
<img src="logo.png" width="206" height="147" />
<p>-Where everything is at your finger tips-</p>
<p>
<label for="usernameText"><label>Username: </label></label>
<input type="text" name="usernameText" id="usernameText" />
</p>
<p>
<label for="passwordText"><label>Password: </label></label>
<input type="password" name="passwordText" id="passwordText" />
</p>
</center>
<center>
<input type="submit" name="create" id="create" onclick="checkCookie()" value="Login" />
<input type="submit" name="check" id="check" onclick="setCookie(
document.getElementById('usernameText').value,
document.getElementById('passwordText').value,365);" value="Register" />
</p>
<p><a href="/">Fight SOPA now!</a></p>
<p><!--[if lt IE 7]>
<div style=' clear: both; height: 59px; padding:0 0 0 15px; position: relative;'> <a href="">
<img src=".jpg" border="0" height="42" width="820" alt="You are using an outdated browser. For a faster, safer browsing experience, upgrade for free today." />
</a></div> <![endif]--><footer><font color="#CCCCCC">Copyright 2012, All Rights Reserved.</font></footer></p>
</center>
</body>
</html>
So, I have a button where if the person's username and password is correct, it will notify you, then it will redirect to another page. The first thing works, but it will not redirect you to the page.
Here is the code of the webpage:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Siur</title>
<script type="text/javascript">
///////////////////////////Login System///////////////////////////
function getCookie(){
var whole, username, password, splitting, actual,user, pass;
whole = document.cookie;
whole = whole.split(';');
username = whole[0];
password = whole[1];
actual = password.split('=');
user = actual[0];
pass = actual[1];
alert(user + password);
}
function setCookie(c_name,value,exdays){
var c_value=value + ";
pass="+document.getElementById('passwordText').value;
document.cookie="=" + value + ";
pass="+document.getElementById('passwordText').value;
alert(document.cookie);
getCookie();
}
function url(url){
document.open(url);
}
function checkCookie(){
var whole, username, password, splitting, actual,user, pass;
whole = document.cookie;
whole = whole.split(';');
username = whole[0];
password = whole[1];
actual = password.split('=');
user = actual[0];
pass = actual[1];
if (document.getElementById('usernameText').value !=null &&
document.getElementById('usernameText').value!="" &&
document.getElementById('passwordText').value == pass) {
alert("Wele again " + user);
document.open('search_webpage.html');
}
else{
alert('Incorrect username or password.');
}
}
//////////////////////////////End of Login system////////////////////////////////////
</script>
</head>
<body>
<table width=100% height=30 background="nav.png" border="0">
<tr>
<td >
<form id="form1" name="form1" method="post" action="">
<label for="searchBox"></label>
IN-DEV 0.1
</form>
</td>
</tr>
</table>
<img src="logo.png" width="206" height="147" />
<p>-Where everything is at your finger tips-</p>
<p>
<label for="usernameText"><label>Username: </label></label>
<input type="text" name="usernameText" id="usernameText" />
</p>
<p>
<label for="passwordText"><label>Password: </label></label>
<input type="password" name="passwordText" id="passwordText" />
</p>
</center>
<center>
<input type="submit" name="create" id="create" onclick="checkCookie()" value="Login" />
<input type="submit" name="check" id="check" onclick="setCookie(
document.getElementById('usernameText').value,
document.getElementById('passwordText').value,365);" value="Register" />
</p>
<p><a href="http://blacklist.eff/">Fight SOPA now!</a></p>
<p><!--[if lt IE 7]>
<div style=' clear: both; height: 59px; padding:0 0 0 15px; position: relative;'> <a href="http://windows.microsoft./en-US/internet-explorer/products/ie/home?ocid=ie6_countdown_bannercode">
<img src="http://storage.ie6countdown./assets/100/images/banners/warning_bar_0000_us.jpg" border="0" height="42" width="820" alt="You are using an outdated browser. For a faster, safer browsing experience, upgrade for free today." />
</a></div> <![endif]--><footer><font color="#CCCCCC">Copyright 2012, All Rights Reserved.</font></footer></p>
</center>
</body>
</html>
Share
Improve this question
asked Feb 10, 2012 at 6:09
user1124927user1124927
2 Answers
Reset to default 4document.open()
is not used to go to a new URL. It is called when you use document.write()
. It will clear the current page.
You want to use window.location = 'http://example.';
.
first of all, its generally not a real good idea to use a variable name that also refers to a function. And I observed alot of issues in your basic HTML code, as the first stage itself try to write proper and follow the best practices.
for the following
function url(url){
document.open(url); //is url the function or the variable?
}
Use as follows
function goto_url(url) {
window.location.href = url; //I think this might be what you are looking for
}
On a totally seperate note, validating the user's password using javascript is like a bank asking you if your check is good before agreeing to cash it.
My apologies, I meant window.location.href
, but could cause a history loop if they click the back button.. Perhaps better to use window.location.replace(url)
本文标签: javascriptDocumentOpen() is not workStack Overflow
版权声明:本文标题:javascript - Document.Open() is not work - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744117627a2591586.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论