2

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

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.

| |
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.