0

我目前正在使用以下脚本从 VBulletin 调用 5 个最新的活动线程:

<script type="text/javascript" src="http://[VBulletin]/external.php?forumids=1&type=js">
</script> 
<script language="" type="text/javascript">
<!--
for (x = 0; x < 5; x++)
{
document.writeln("<a href=\"http://[VBulletin]/showthread.php?t=" +threads[x].threadid+"\">"+threads[x].title+"</a> (Posted By: "+threads[x].poster+")<br />");
}
</script>

我想让填充的论坛链接在父页面的 iFrame 中打开(上面的代码在所述页面的辅助 iFrame 中)。在标准 HTML 中,它将是:<a href="link" base target="pageframe">,但我不确定如何在上述代码中的 JS 中执行相同的功能。

提前致谢!

4

1 回答 1

0

Asuming all of this is on the same domain, and that your target iframe had an id like <iframe id="openlinkshere"> You could add a handler on your links like this:

<script type="text/javascript" src="http://[VBulletin]/external.php?forumids=1&type=js">
</script> 
<script language="" type="text/javascript">
<!--
for (x = 0; x < 5; x++)
{
document.writeln("<a onclick=\"top.document.getElementById('openlinkshere').location.href = this.href; return false;\" href=\"http://[VBulletin]/showthread.php?t=" +threads[x].threadid+"\">"+threads[x].title+"</a> (Posted By: "+threads[x].poster+")<br />");
}
</script>

This would open the link on your target iframe

top.document.getElementById('openlinkshere').location.href = this.href; 

This stops event propagation so your "list" iframe stays where it is.

return false;

于 2013-07-03T18:45:15.783 回答