【问题标题】:iframe: Subsequent clicks loads the new url in a new tabiframe:后续点击会在新标签页中加载新网址
【发布时间】:2012-12-19 16:45:24
【问题描述】:

!!求救!!

问题背景:我有一个文件,其中包含一些页面标题和相应的 URL。我正在动态读取此文件并生成一个表格,其中每一行都显示(可点击)标题。页面上有一个 iframe。我希望当用户单击其中一行时,相应的页面应该加载到 iframe 中。这些 url 可能属于不同的域。

主要问题:第一次点击在iframe中完美打开对应的url。但是,任何后续点击(在同一行或不同行上)都会在新窗口中打开 url,而不是替换 iframe 中的早期 url。

用谷歌搜索了很久,但似乎这个问题仍未解决(很多空帖子没有回复:-()

请回复此帖。如果需要,我很乐意为您提供更多信息/代码。

问候 P

PS:顺便说一下,这个更简单的 html 代码也发生了同样的事情。只有两个链接和一个 iframe。复制粘贴此 html 文件并尝试。一个链接将加载 iframe 中的内容,另一个链接将重定向到新选项卡 :x :x

<html>
<table>
<tr><td><a style="text-decoration:none; line-height: 150%; color:darkslategray;" href="http://www.usatoday.com/story/money/markets/2013/01/04/stocks-higher-bull-market-high/1810075/" target="main_frame">GM, Peugeot to Decide on Brazil Factory This Month, Veja Says <br>Bloomberg News &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2012-05-19</a></td></tr>
<tr><td><a style="text-decoration:none; line-height: 150%; color:darkslategray;" href="http://www.reuters.com/article/2013/01/04/us-markets-stocks-idUSBRE8BG0D620130104" target="main_frame">GM, Peugeot no Decide on Brazil Factory This Month, Veja Says <br>Bloomberg News &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2012-05-20</a></td></tr>
</table>

<iframe name="main_frame" frameborder="0" marginheight="0" marginwidth="0" scrolling="yes" height="100%" width="100%" src=""></iframe>

</html>

在 chrome 和 firefox 上测试。

【问题讨论】:

    标签: html google-chrome firefox iframe


    【解决方案1】:

    解决了!!!

    使用这两个链接:https://developer.mozilla.org/en-US/docs/HTML/Element/iframeFirefox opens links targeted for iFrame in browser's new tab instead

    以及以下代码:

    <html>
    <head>
    <script type="text/javascript">
    function navigate(url)
    {
        var iframe = document.getElementsByTagName( "iframe" )[0];
        iframe.src = url;
    }
    </script>
    </head>
    
    <body>
    <table>
    <tr><td><a href="javascript:navigate('http://www.usatoday.com/story/money/markets/2013/01/04/stocks-higher-bull-market-high/1810075/')">Some title</a></td></tr>
    <tr><td><a href="javascript:navigate('http://www.reuters.com/article/2013/01/04/us-markets-stocks-idUSBRE8BG0D620130104')">Some Other title</a></td></tr>
    </table>
    
    <iframe name="main_frame" frameborder="0" marginheight="0" marginwidth="0" scrolling="yes" height="100%" width="100%" src=""></iframe>
    
    </body>
    </html>
    

    【讨论】:

      【解决方案2】:

      其中一个网页更改了其窗口的window.name,并且通过窗口名称而不是框架名称进行定位...

      【讨论】:

      • 您有什么建议,我该如何解决??
      • 另外,如果一个网页更改了window.name,为什么我第一次点击链接时,它会在iframe中打开?
      • 第一次点击链接,改名的网页还没有加载。至于如何解决...我实际上不确定。您可以根据脚本位置集进行各种黑客攻击,这可能是这里最简单的事情。这真的取决于你的其他约束是什么。
      猜你喜欢
      • 2013-06-26
      • 1970-01-01
      • 1970-01-01
      • 2018-02-25
      • 1970-01-01
      • 2014-07-11
      • 1970-01-01
      • 2017-09-13
      • 1970-01-01
      相关资源
      最近更新 更多