简体   繁体   English

在iframe中的新标签页/窗口中打开处理

[英]handeling open in new tab/window inside iframe

i am having a simple web application with side menu and an iframe, and everything in the application loads inside the iframe, however if user opened a link in new tab/window the page will open separately without the main page, what i want to achieve is when user opens a link in new tab, the main page with iframe loads in the new page with the targeted url inside the iframe, so is it possible to do that? 我有一个带有侧面菜单和iframe的简单Web应用程序,该应用程序中的所有内容均加载到iframe中,但是,如果用户在新标签页/窗口中打开了一个链接,则该页面将单独打开而没有主页,这是我想要实现的目标是当用户在新标签页中打开链接时,具有iframe的主页会加载到iframe中具有目标网址的新页面中,那么有可能这样做吗? simple example of main page: 主页的简单示例:

<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>

You need to use some little javascript to do that. 您需要使用一些小javascript来做到这一点。

Try this: 尝试这个:

<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>

Cheers. 干杯。

Also experiment with this: 也可以尝试一下:

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

The HTML would look like in my previous answer. HTML看起来像我之前的答案。 :) :)

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM