回答
我發現最好的解決方案是使用基地標籤。將以下內容添加到iframe頁面的頭部:
<base target="_parent">
這將加載父窗口中頁面上的所有鏈接。如果你希望你的鏈接,加載在一個新的窗口,使用:
<base target="_blank">
此標記在所有瀏覽器fully supported。
使用目標屬性:
<a target="_parent" href="http://url.org">link</a>
嘗試target="_parent"
屬性的anchor tag
內。
如上所述,您可以使用目標屬性,但它在技術上已在XHTML中棄用。這留下了您使用JavaScript,通常像parent.window.location
。
有一個DOM對象調用base
它允許你:「指定頁面上的所有鏈接默認URL和默認的目標:」通過指定「_blank」
<base target="_blank" />
你要確保裏面的所有鏈接iframe將在外部打開。
使用JavaScript:
window.parent.location.href= "http://www.google.com";
<a target="parent">
在新標籤/窗口將打開鏈接... <a target="_parent">
將打開在父/當前窗口的鏈接,而無需打開新的標籤頁/窗口。 Don't_forget_that_underscore!
最通用的和最跨瀏覽器的解決方案是避免使用「基地」標籤的,而是用「a」標記的目標屬性:
<a target="_parent" href="http://www.stackoverflow.com">Stack Overflow</a>
的<base>
標籤是功能較少,瀏覽器在文檔中的位置要求不一致,需要更多的跨瀏覽器測試。根據您的項目和情況,實現<base>
標籤的理想跨瀏覽器放置可能很困難,甚至完全不可行。
使用<a>
標記的target="_parent"
屬性執行此操作不僅更適合瀏覽器,還允許您區分要在iframe中打開的那些鏈接以及要在父級打開的鏈接。
如果您在網頁中使用iframe,則可能會在通過iframe中的HTML超鏈接(錨標記)更改整個頁面時遇到問題。有兩種解決方案可以緩解這個問題。
解決方案1.您可以使用以下示例中給出的錨標記的目標屬性。
<a target="_parent" href="http://www.kriblog.com">link</a>
解決方案2.您也可以在iframe和JavaScript的父窗口中打開一個新頁面。
<a href="#" onclick="window.parent.location.href='http://www.kriblog.com';">
記住⇒target="_parent"
已過時,XHTML,但它仍然是在HTML 5.x中支持
更可以從下面的鏈接 http://www.kriblog.com/html/link-of-iframe-open-in-the-parent-window.html
讀你可以使用任何選項
只有父頁面的情況下:
,如果你想打開所有鏈接到父頁面或父級iframe中,然後在iframe的頭部分中使用以下代碼:
<base target="_parent" />
OR,如果你想開一家特定鏈接到父頁面或父IFRAME
,那麼您可以採取以下方式:
<a target="_parent" href="http://specific.org">specific Link</a>
<a href="http://normal.org">Normal Link</a>
OR
萬一嵌套iframe的:
如果想打開所有鏈接到瀏覽器窗口(在瀏覽器的URL重定向),那麼您可以採取以下的iframe的頭部分代碼:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script type="text/javascript">
$(window).load(function(){
$("a").click(function(){
top.window.location.href=$(this).attr("href");
return true;
})
})
</script>
OR
如果要打開特定鏈接進入瀏覽器窗口(在瀏覽器url中重定向),則使用以下方法:
<a href="http://specific.org" target="_top" >specific Link</a>
或
<a href="javascript:top.window.location.href='your_link'">specific Link</a>
<a href="javascript:top.window.location.href='http://specific.org'">specific Link</a>
<a href="http://normal.org">Normal Link</a>
耶,我發現
<base target="_parent" />
這個有用的開放在iframe中打開的所有鏈接的iframe。
而且
$(window).load(function(){
$("a").click(function(){
top.window.location.href=$(this).attr("href");
return true;
})
})
這一點我們可以使用整個網頁或網頁的特定部分。
謝謝大家的幫助。
<script type="text/javascript"> // if site open in iframe then redirect to main site
$(function(){
if(window.top.location != window.self.location)
{
top.window.location.href = window.self.location;
}
});
</script>
嘗試target="_top"
<a href="http://example.com" target="_top">
This link will open in same but parent window of iframe.
</a>
- 1. 當iframe不是來自同一個域時,如何強制從iframe中打開父窗口中的鏈接?
- 2. 將iframe中的Silverlight Web部件鏈接強制爲在父窗口中打開
- 3. iframe強制鏈接在當前窗口中打開
- 4. 父窗口中的iframe中的打開鏈接
- 5. iframe中的鏈接在父窗口中打開
- 6. 強制iframe提交在父窗口中打開
- 7. 在父窗口中打開iframe的鏈接
- 8. 在父窗口的新選項卡中打開Iframe鏈接
- 9. 如何強制鏈接在新窗口中自動打開?
- 10. 如何強制Selenium在新窗口中打開鏈接?
- 11. 強制iFrame鏈接(在嵌入的Google Doc中)在新窗口中打開
- 12. 在父窗口中打開iFrame中的鏈接(無法控制子網站)
- 13. 如何在父窗口中打開放置在IFRAME中的鏈接
- 14. 如何只打開父窗口上的iframe中的一些鏈接
- 15. 如何強制在新窗口打開電子郵件鏈接
- 16. 如何打開將iframe源打開到新窗口的iframe之外的鏈接?
- 17. 如何從父窗口頂部的iframe中打開colorbox
- 18. iframe中的鏈接更改父窗口
- 19. 如何在彈出的iframe窗口中打開鏈接
- 20. 如何通過iframe中的鏈接打開新窗口
- 21. 是什麼導致iframe在父窗口內打開新鏈接?
- 22. 如何從iframe窗口打開Javascript彈出窗口到父窗口
- 23. 打開從iFrame到父窗口的模態窗口
- 24. 如何打開父項中的iframe鏈接到iframe
- 25. Xulrunner強制鏈接在單個窗口中打開
- 26. 強制HTML鏈接在新窗口中打開
- 27. 強制鏈接在新窗口中打開
- 28. 從iframe打開模式窗口進入父窗口
- 29. 從iframe打開窗口
- 30. iOS:從htmlpage強制打開'safari窗口'
我試試這個,是我在新窗口中 – 2009-06-24 11:52:17
+1開放,基本目標=「_父」的作品,但目標=「_父」,決不放過我! – 2012-03-14 05:18:56
它適用於SVG! – Rustam 2012-06-22 11:28:31