【问题标题】:Managing <iframe> in a jsp page在 jsp 页面中管理 <iframe>
【发布时间】:2013-12-29 15:03:07
【问题描述】:

我有一个导航栏,它有四个链接,点击任何链接,相应页面在导航栏下方的框架中打开,但是当我使用右键单击在新选项卡中打开时,我希望打开整个页面,即打开特定链接不允许单独在新标签页中使用

链接应该单独打开或显示在框架中,而不是单独打开。这可以做到吗?

 <a href="page1.jsp" target="frame1">page1</a>
 <a href="page2.jsp" target="frame1">page2</a>
 <iframe name="frame1" src="page3.jsp">

右键单击链接并在新窗口中打开应该会再次启动整个应用程序。

【问题讨论】:

    标签: javascript html jsp iframe coffeescript


    【解决方案1】:

    应该只在 iframe 中显示的每个页面(page1.jsp、page2.jsp 和 page3.jsp)都应该包含 JS 来检测它是否显示在自己的窗口中。例如,如果带有 iframe 的页面是 index.jsp,则 page1.jsp 应包含以下代码:

    <script type="text/javascript">
    <!--
    if (top.location.href == self.location.href)
      // Redirect user to main page, passing current page name:
      top.location.href = 'index.jsp?frame=page1';
    //-->
    </script>
    

    然后,在 index.jsp 中,您应该使 iframe 的 src 加载指定的帧源:

    <% 
    // Establish default source:
    String frame_src = 'page3.jsp';
    // Establish controlled list of pages to show in the iframe (important to be restrictive)
    String[] allowed_srcs = ['page1','page2','page3'];
    // Get targeted frame from query string, if given:
    String targeted_frame = request.getParameter('frame');
    if(Arrays.asList(allowed_srcs).contains(targeted_frame))
      frame_src = targeted_frame + '.jsp';
    %>
    <iframe name="frame1" src="<%= frame_src %>"></iframe>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-20
      • 2014-02-25
      • 1970-01-01
      • 2011-06-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多