2012-07-22 105 views
2

我有一個簡單的帶有側邊菜單和iframe的web應用程序,並且應用程序中的所有內容都在iframe中加載,但是如果用戶在新選項卡/窗口中打開鏈接,頁面將會在沒有主頁的情況下單獨打開,我想要實現的是當用戶在新選項卡中打開鏈接時,帶有iframe的主頁面會在新頁面中加載iframe中的目標url,那麼可以這樣做嗎?主要頁面的 簡單的例子:handeling在iframe中的新選項卡/窗口中打開

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

回答

0

你需要使用一些小的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> 

乾杯。

0

而且這個實驗:

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

的HTML看起來像我以前的答案。 :)

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