2017-10-06 51 views
0

我有一个iframe(Java servlet为)的网站,该网站看起来有点像这样的问题:在基于iframe的网站中,如何在用户点击一个iframe中的链接后在新窗口中加载所有iframe?

<!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>

因为每个I帧的是一个独立的网页,如果用户决定从任何iframe中打开链接,在新窗口或标签页中加载的页面看起来破碎,因为它只是整个网站的一部分。

我想知道是否有方法检测用户是否从浏览器中选择了“在新选项卡中打开”或“在新窗口中打开”。然后,我必须确保在发生这种情况后,所有的iframe都会加载到新窗口中。

让我知道是否还有更好的解决方案。

+1

为什么你需要做的是什么?每种情况下你都会发送一个不同的呈现iframe? – Kalamarico

+0

我正在使用的应用程序已经建立了一段时间,并且有人决定使用HTML5中不支持的** frameset **。因此,我们将其更改为** iframes **。我刚刚在下面的评论中描述了这个问题:“如果有人决定使用右键单击上下文菜单并选择”在新窗口中打开链接“,则只会打开链接所在的iframe,例如,如果我尝试从**内容** iframe中打开一个链接,只有没有**顶部**和**页脚**的这个iframe将被加载到新窗口中,所以页面看起来会被破坏。“ – rmatuszczak

回答

1

使用目标属性可以解决用户在浏览iframe时遇到的问题。

你的iFrame是已命名顶部内容,并页脚。您还可以将三个iframe放置在父iframe中,然后您可以将其命名为main_iframe

然后,对于您的链接,请指定您希望它们在使用目标属性时打开的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> 

然后,您可以禁用oncontextmenu使用Javascript 右键单击事件:

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

不幸的是,这个解决方案并没有解决我的问题。我已经在使用** target **属性来浏览应用程序。但是,如果有人决定使用右键单击上下文菜单并选择“在新窗口中打开链接”,则只会打开链接所在的iframe。例如,如果我尝试从** content ** iframe中打开一个链接,只有没有** top **和** footer **的这个iframe将被加载到新窗口中,所以页面看起来会被破坏。 – rmatuszczak

相关问题