2013-02-22 168 views
0

我使用下面的代碼在函數返回成功消息時打開一個新窗口。同時我想關閉自我窗口。現在正在錯誤:使用javascript在aspx中打開窗口

newwindow is not defined

var value = getQueryStrings(); 
var cust_id = value["cust_id"]; 
try { 

    PageMethods.add_plan_items(unescape(items), cust_id, device, OnGetMessageSuccess, OnGetMessageFailure); 

} catch (ex) { 
    alert(ex); 
} 

function OnGetMessageSuccess(result, userContext, methodName) { 
    try { 
     var ret_array = result.toString().split(':'); 
     if (ret_array[0] == "Success Alert ") { 

      var left = (screen.width/2) - 1015/2; 
      var top = (screen.height/2) - 550/2; 

      self.close(); //Close the opened window 

      //Enter here and self window is closed 

      var newwindow = window.open('test.aspx?id=Y&cust_id=' + cust_id, 'Add Items', 'height=550,width=1000,toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,left=' + left + ', top=' + top + ',screenX=' + left + ',screenY=' + top + ''); 
      if (window.focus) { 
       newwindow.focus() 
      } 
      return false; 
     } else { 
      self.close(); //Close the opened window 
      alert('Error Alert : Error for adding plans in your specified device. Please try again later!'); 
     } 

    } catch (ex) { 
     alert(ex); 
    } 

} 

function OnGetMessageFailure(error, userContext, methodName) { 
    alert(error.get_message()); 
} 
+0

打開子窗口後關閉父項。 – nsthethunderbolt 2013-02-22 07:10:29

回答

0

不要閉上你的父窗口第一
保存父窗口,然後打開您的子窗口(新窗口),然後關閉你的父窗口

var parentWindow = self.window; 
var newWindow = window.open(...); 

parentWindow.close(); 
+0

現在我得到一個錯誤newWindow爲空。 – user1951007 2013-02-22 07:10:05

+0

你原來的代碼中的'newwindow'很小,在我的代碼中w是大寫的。更改 – asifsid88 2013-02-22 07:11:57

+0

感謝您的回覆。現在我改變newwindow而不是newWindow。但是我遇到了一個新的錯誤控件,必須在頁面的控件樹中。 – user1951007 2013-02-22 07:41:20