iframe:后续点击会将新网址加载到新标签中 [英] iframe: Subsequent clicks loads the new url in a new tab
问题描述
!! SOS !!
问题背景:我有一个文件,其中包含一些页面标题和相应的URL。我正在动态读取这个文件,并生成一个表,每行显示(可点击)标题。页面上有一个iframe。我希望当用户点击其中一个行时,相应的页面应该加载到iframe中。这些网址可能属于不同的网域。
主要问题:第一个点击完全在iframe中打开相应的网址。但是,随后的任何点击(位于同一行或不同行)将在新窗口中打开该网址,而不是替换iframe中较早的网址。
尝试了很长时间的搜索,但似乎这个问题仍然没有解决(大量的空帖子没有答复: - ()
请回复这篇文章,如果需要,我会很乐意为您提供更多的信息/代码。
问候
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通用汽车,标致决定在巴西本月工厂,Veja说 彭博新闻& nbsp;& nbsp;& nbsp; 2012-05-19< / a>< / td> < / TR>
< tr>< td>< a style =text-decoration:none; line-height:150%; color:darkslategray;通用汽车,标致没有决定巴西工厂本月,Veja说< href =http://www.reuters.com/article/2013/01/04/us-markets-stocks-idUSBRE8BG0D620130104target =main_frame> ;彭博新闻& nbsp; &安培; NBSP; &安培; NBSP; &安培; NBSP; &安培; NBSP; 2012-05-20< / A>< / TD>< / TR>
< / table>
< / html>
在Chrome和Firefox上测试。解决方案解决方案!!!
使用这两个链接: https://developer.mozilla.org/zh-CN/docs/ HTML / Element / iframe
和
和以下代码片段:
< html>
< head>
< script type =text / javascript>
函数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 /')>部分标题< / a>< / td>< / tr>
< tr>< td>< a href =javascript:navigate('http://www.reuters.com/article/2013/01/04/us-markets-stocks-idUSBRE8BG0D620130104') >部分其他标题< / a>< / td>< / tr>
< / table>
< / body>
< / html>
!! SOS !!
Problem Background: I have a file which contains some page titles and corresponding URLs. I am reading this file dynamically and generating a table with each row showing the (clickable) title. There is one iframe on the page. I want that when a user clicks on one of the rows, the corresponding page should get loaded in the iframe. These urls may belong to different domains.
Main Issue: The first click opens the corresponding url perfectly in the iframe. However, any subsequent clicks (on the same or different row), opens the url in a new window, instead of replacing the earlier url in the iframe.
Tried googling it for long, but it appears that this problem is still unresolved (lots of empty posts without replies :-()
Please reply to this post. I will be happy to provide you with much more information/code if required.
Regards P
PS: By the way, the same thing is happening with this simpler html code. Just two links and one iframe. Copy-paste this html file and try. One link will load the content in iframe and the other will redirect to a new tab :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 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 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>
Tested on both chrome and firefox.
Solved it !!!
Used these two links: https://developer.mozilla.org/en-US/docs/HTML/Element/iframe and Firefox opens links targeted for iFrame in browser's new tab instead
and the following piece of code:
<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>
这篇关于iframe:后续点击会将新网址加载到新标签中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!