簡體   English   中英

在基於iframe的網站中,用戶單擊一個iframe中的鏈接后,如何在新窗口中加載所有iframe?

[英]In an iframe based website, how to load all iframes in a new window after user clicks on a link within one iframe?

我在基於iframe(Java Servlet)的網站上遇到問題,該網站看起來像這樣:

 <!DOCTYPE html> <head></head> <body> <iframe id="top" name="top" src="$link.setAction('top').relative()"></iframe> <iframe id="content" name="content" src="$link.setAction('content').relative()"></iframe> <iframe id="footer" name="footer" src="$link.setAction('footer').relative()"></iframe> </body> </html> 

由於每個iframe都是獨立頁面,因此,如果用戶決定從任何iframe中打開鏈接,則新窗口或標簽中加載的頁面將顯示為已損壞,因為它只是整個網站的一部分。

我想知道是否有一種方法可以檢測用戶是從瀏覽器中選擇了“在新選項卡中打開”還是“在新窗口中打開”。 然后,我必須確保在這種情況發生之后,所有iframe都加載到一個新窗口中。

讓我知道是否還有更好的解決方案。

當用戶在iframe中導航時,請使用target屬性解決您的問題。

您的iframe已被命名為topcontentfooter 您還可以將三個iframe放置在父iframe中,然后可以將其命名為main_iframe

然后為您的鏈接使用target屬性指定您希望它們打開的iframe的名稱。

<a href="top.html" target="top">Example link inside the top frame which opens only in top frame</a>
<a href="content.html" target="content">Example link inside the content frame</a>
<a href="bottom.html" target="bottom">Example link inside the bottom frame</a>

<a href="main.html" target="main_iframe">Example link which opens in the parent frame</a>

然后,您可以使用Javascript oncontextmenu禁用右鍵單擊事件:

    window.oncontextmenu = function() {
        return false;
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM