【问题标题】:handeling open in new tab/window inside iframe处理在 iframe 内的新选项卡/窗口中打开
【发布时间】:2012-07-22 19:16:27
【问题描述】:

我有一个带有侧边菜单和 iframe 的简单 Web 应用程序,应用程序中的所有内容都加载到 iframe 中,但是如果用户在新选项卡/窗口中打开链接,则页面将在没有主页的情况下单独打开,我该怎么做想要实现的是当用户在新选项卡中打开一个链接时,带有 iframe 的主页会在新页面中加载,目标 url 在 iframe 内,那么可以这样做吗? 主页的简单示例:

<html>
<head></head>
<body>
<div class='menu'>
<ul>
<li><a target='con' href='somepage.php'>item 1</a></li>
<li><a target='con' href='otherpage.php'>item 2</li>
</ul>
</div>
<iframe id='con' class='container'></iframe>
</body>
</html>

【问题讨论】:

    标签: javascript jquery iframe


    【解决方案1】:

    你需要使用一些小的 javascript 来做到这一点。

    试试这个:

    <html>
    <head></head>
    <script>
        function func(linker){
            top.frames['con'].location.href = linker;
        }
    </script>
    <body>
    <div class='menu'>
    <ul>
    <li><a onclick="func('somepage.php')">item 1</a></li>
    <li><a onclick="func('otherpage.php')">item 2</a></li>
    </ul>
    </div>
    <iframe id='con' class='container'></iframe>
    </body>
    </html>
    

    干杯。

    【讨论】:

      【解决方案2】:

      也可以试试这个:

      function func(linker){
          document.getElementById('iframe').setAttribute('src',''page1.html');
      }
      

      HTML 看起来像我之前的回答。 :)

      <li><a onclick="func('somepage.php')">item 1</a></li>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-06-12
        • 1970-01-01
        • 2020-07-10
        • 2014-02-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多