2012-07-22 100 views
2

我有一个简单的带有侧边菜单和iframe的web应用程序,并且应用程序中的所有内容都在iframe中加载,但是如果用户在新选项卡/窗口中打开链接,页面将会在没有主页的情况下单独打开,我想要实现的是当用户在新选项卡中打开链接时,带有iframe的主页面会在新页面中加载iframe中的目标url,那么可以这样做吗?主要页面的 简单的例子:handeling在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> 

回答

0

你需要使用一些小的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> 

干杯。

0

而且这个实验:

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

的HTML看起来像我以前的答案。 :)

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