javascript - 处理在 iframe 内的新选项卡/窗口中打开

标签 javascript jquery iframe

我有一个带有侧边菜单和 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/

相关文章:

javascript - 我应该如何使用联系表单 7 (wp) 正确捕获提交的表单值?

javascript - 如何在事件中通过 sibling 循环类(class)

jquery - Rails 与 JQuery fileupload 给出了预期的数组(得到 Rack::Utils::KeySpaceConstrainedParams

javascript - iframe 中的按钮应触发事件

jquery - 从 iframe 调用父级中的 Fancybox

javascript - 获取 jquery .post() 函数的结果

java - 如何使用斑马小程序在收据打印机中打印

javascript - IScriptControl - 更新 javascript

javascript - 使用 Jquery 遍历表单中的元素

javascript - 在 AngularJS 中插入来自可信源的 iframe