首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> 更多程式語言 >> 程式設計疑難解答

ASP.NET iframe 內跳轉至頂層頁面:target="_blank" 或 window.open('_top')

     編輯:程式設計疑難解答

場景

iframe 頁面按鈕點擊後,需在**頂層視窗**打開新頁面(跳出 iframe)。

方案一:表單/連結 target="_top"

<form action="target.aspx" target="_top" method="post">
    <button type="submit">跳轉</button>
</form>

<a href="target.aspx" target="_top">跳轉</a>

方案二:JavaScript window.open

// 按鈕 onclick
window.open('target.aspx', '_top'); // _top 表示頂層視窗
// 或
window.open('target.aspx', '_blank'); // 新分頁

方案三:服務端 Response.Redirect (無效)

Response.Redirect("target.aspx") 僅導致 **iframe 內部** 跳轉,無法跳出。必須配合客戶端腳本。

最佳實踐

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved