简体   繁体   中英

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

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. :)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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