2012-05-05 49 views
1

我試圖在加載與灰色背景的開始頁面中間的iframe中顯示我的登錄內容,但是我遇到了處理iframe目標的問題,應按照以下方式進行操作: 1-如果用戶登錄成功,主頁應加載到父窗口中 2-如果錯誤,應在iframe中顯示錯誤消息本身。動態更改窗體的目標

我的代碼:

<div id="cover5" onclick="javascript:cover5();"> 
     <iframe name="warning" src="SignIn.php" id="warning" onclick="javascript:cover5();"> 
     </iframe> 
    </div> 

SignIn.php

<html> 
    <head> 
     <script type='text/javascript'> 
    function valid(){ 
    if(document.getElementById('username').value.toString().length>=1 || document.getElementById('password').value.toString().length>=1){ 
    return true; 
    } 
    else{ 
    alert("The Combination of username and password are Incorrect !"); 
    return false; 
    } 
    } 
</script> 
<script type='text/javascript'> 
function ChangeTarget() { 
    document.getElementById("login").prop("target", "_parent") 
} 
</script> 
<script type='text/javascript'> 
function ChangeText(text) { 
       document.getElementById("label1").innerHTML= text; 

      } 
     </script> 
     <title></title> 
    </head> 
    <body> 
<form name="login" id='login' target='_self' method='post' accept-charset='UTF-8'> 
<fieldset> 
<legend>SignIn</legend> 
<input type='hidden' name='submitted' id='submitted' value='1'/> 
<label for='username' >Email:</label> 
<input type='text' name='email' id='username' maxlength="50" /> <br /> 
<label for='password' >Password:</label> 
<input type='password' name='password' id='password' maxlength="50" /> <br /> 
<br /> <label id="label1" style="color: red"></label> <br /> 
<input type='submit' name='Submit' value='Login'/> <br /> 
<a href='resetPassword1.php'> Forgot/Reset Password? Click Here</a> 
</fieldset> 
</form> 

然而,目標不被法ChangeTarget(),它被稱爲inisde PHP代碼改變,所以現在的問題是,一切都加載內部框架或父窗口內的所有內容。任何人都知道如何解決這個問題?

服務器端腳本:

mysql_select_db("mydb",$check); 
$email = $_POST['email']; //username that will be submit from a form 
$password = $_POST['password']; //password that will be submit from a form 

    // if(mysql_num_rows($temp_privileges_id)== 1) //if the id found that means that the user is already assigned to a conference 
    // { 
      echo '<script type="text/javascript">', 
      'ChangeTarget();', 
      '</script>'; 
      header('Location: main.php'); // transefer to home page with variable username 
    } 
+0

代碼調用ChangeTarget是服務器端?請提供有關該部分的更多細節。 –

+0

@KevinCollins完成 –

+0

@KevinCollins我能正確調用函數嗎? –

回答

1

沒有方法prop。任一組的target屬性的值直接

document.getElementById("login").target = "_parent"; 

,或者使用setAttribute

document.getElementById("login").setAttribute("target", "_parent"); 
0

.prop()是一個jQuery功能。如果你打算這樣做jQuery的,這樣做:

$("#login").prop("target", "_parent"); 

如果你不打算這樣做jQuery中,像這樣做的直接的JavaScript:

document.getElementById("login").target = "_parent";