我有一个带有侧边菜单和 iframe 的简单网络应用程序,应用程序中的所有内容都加载到 iframe 中,但是如果用户在新选项卡/窗口中打开链接,页面将单独打开而没有主页面,我想要实现的是,当用户在新选项卡中打开链接时,带有 iframe 的主页会加载到新页面中,并在 iframe 中使用目标 url,所以可以这样做吗? 主页的简单示例:
<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>
干杯。
关于javascript - 处理在 iframe 内的新选项卡/窗口中打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11603265/