Asp.net

iFrame中的Response.Redirect(),重定向父視窗

  • May 15, 2019

我知道這是不可能的,但是想要Response.Redirect從 iFrame 重定向父頁面的最佳選擇是什麼?

使用 ASP.NET 無法做到這一點。伺服器端的 ASP.NET 可以重定向傳入請求並且不知道父框架。

但是,如果您想在某些伺服器端條件下重定向父框架,您可以從伺服器呼叫 JavaScript,如下所示:

protected void Page_Load(object sender, EventArgs e) {
  ClientScriptManager.RegisterClientScriptBlock(this.GetType(), 
      "RedirectScript", "window.parent.location = 'http://yoursite.com'", true);
}

當然,您可以在客戶端使用簡單的 JavaScript window.parent.location = ‘http://yoursite.com’。

引用自:https://stackoverflow.com/questions/7307285