0

!!求救!!

问题背景:我有一个文件,其中包含一些页面标题和相应的 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 上测试。

4

2 回答 2

1

解决了!!!

使用了这两个链接:https ://developer.mozilla.org/en-US/docs/HTML/Element/iframe 和Firefox 在浏览器的新选项卡中打开针对 iFrame 的链接

和以下代码:

<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>
于 2013-01-08T00:57:21.137 回答
0

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

于 2013-01-06T06:23:58.393 回答