2017-03-07 135 views
2

這是事件處理程序我設置了一個按鈕:爲什麼document.location或window.location不能工作?

$('.tabsTD').on('click', 'a.finalSave', (function() { 
    var returnStatus= finalSave(this, location); 

    if (returnStatus) { 
     if ($(this).text() == "Save and Continue") { 
      sessionStorage.carePlanReload = "true"; 
      sessionStorage.activeTab = $('#tabs').tabs("option", "active"); 
      window.event.returnValue = false; 
      document.location.reload(false); 
     } 
     else if ($(this).text() == "Save and Close") { 
      window.event.returnValue = false; 
      document.location = "MemberHome.aspx"; 
      //setTimeout(function() { document.location = "MemberHome.aspx"; }, 500); 
      //return false; 
      //$('#aRedirectToHome')[0].click(); 
      return false; 
     } 
    } /*END if*/ 
})); 

else if情況下,我需要重定向到「memberhome.aspx」,但似乎沒有任何工作。我也嘗試添加一個錨標記,如:

<a href="MemberHome.aspx" id="aRedirectToHome" style="display:none;">RedirectToHome</a> 

,然後從else if調用上的錨一次點擊,但事實證明這是一次失敗的嘗試。

請幫忙。

+1

你能試試嗎? document.location.href =「window.location.protocol + window.location.host + MemberHome.aspx」; –

+0

@LuongDinh請參閱我對第一個答案的評論,並且您錯誤地引用了上述評論 –

回答

1

您需要可以通過一個新值href屬性,如:

window.location.href = "MemberHome.aspx";

,或者使用分配方法爲:

window.location.assign("MemberHome.aspx");

+0

中的聲明,感謝您的回覆,但我儘早嘗試了兩種方式,並且沒有工作,頁面保持不變,不重定向 –

+1

我懷疑它有處理你正在使用的window.event.returnValue表達式。請注意,這是非標準和不推薦使用的功能。您可能想要將該行註釋掉,看看它是否有效。 –

+0

也沒有工作 –