我有一个简单的web应用程序,它有侧菜单和iframe,应用程序中的所有内容都加载在iframe中,但如果用户在新的选项卡/窗口中打开链接,页面将单独打开,而没有主页,我想实现的是,当用户在新选项卡中打开链接时,带有iframe的主页加载在新页面中,目标url位于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>
您需要使用一些小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>
干杯。
还可以进行以下实验:
function func(linker){
document.getElementById('iframe').setAttribute('src',''page1.html');
}
HTML看起来像我之前的回答。:)
<li><a onclick="func('somepage.php')">item 1</a></li>