繁体   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