2012-02-10 9 views
0

人のユーザー名とパスワードが正しいと通知するボタンがあり、別のページにリダイレクトされます。最初のことは機能しますが、ページにリダイレクトされません。ここでDocument.Open()は機能しません

は、Webページのコードです。また、関数に参照する変数名を使用するには、その一般的ではない本当の良いアイデア、すべての

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/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("Welcome 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.org/">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.com/en-US/internet-explorer/products/ie/home?ocid=ie6_countdown_bannercode"> 
    <img src="http://storage.ie6countdown.com/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> 

答えて

3

最初。また、基本的なHTMLコードでは、最初の段階で適切な記述を行い、ベストプラクティスに従うようにしています。次

function url(url){ 
     document.open(url); //is url the function or the variable? 
} 

使用のための

あなたのチェックがに同意する前に良好であれば、銀行はあなたを求めているようにJavaScriptを使用して、ユーザーのパスワードを検証、完全に別々のノートで

function goto_url(url) { 
    window.location.href = url; //I think this might be what you are looking for 
} 

を次のようにそれを現金化する。

私の謝罪は、私がwindow.location.hrefを意味し、彼らはおそらく、より良い

5

document.open()window.location.replace(url)が新しいURLに移動するために使用されていない使用することを... [戻る]ボタンをクリックすると履歴ループを引き起こす可能性があります。 document.write()を使用すると呼び出されます。現在のページをクリアします。

window.location = 'http://example.com';を使用します。

関連する問題