我有一個div叫mainContent
,如果我點擊一個鏈接我要清除maincontent
,從鏈接中iframe
asp.net DIV/iframe和目標
iframe
到div,並打開該頁面
如何去做呢? 我假設一些JS是needeD?
我有一個div叫mainContent
,如果我點擊一個鏈接我要清除maincontent
,從鏈接中iframe
asp.net DIV/iframe和目標
iframe
到div,並打開該頁面
如何去做呢? 我假設一些JS是needeD?
<a href="javascript:SetContent();">Some link</a>
<script>
function SetContent()
{
document.getElementById('mainContent').innerHTML =
"<iframe width=" + screen.width + "px height=" + screen.height +
"px src='http://www.SomeUrl.com'></iframe>";
}
</script>
完美。就是這樣。有沒有辦法用當前分辨率的寬度/高度創建iframe? – user1468537 2012-07-31 09:59:55
是的,你可以使用'screen.width'和'screen.height'訪問分辨率。 – Magnus 2012-07-31 10:06:28
很酷。這工作得很好。 – user1468537 2012-07-31 10:10:58
贊this?
<script type="text/javascript">
function addiframe(){
document.getElementById("maincontent").innerHTML='<iframe name="myiframe"></iframe>';
}
</script>
<div id="maincontent">asd</div>
<a href="//example.com" onclick="addiframe()" target="myiframe">click</a>
試試這個片段。你需要包含jquery庫來使用它。
function appendContent(){
$('#mainContent').html('');
$('#mainContent').html('<iframe name="myiframe" width=620 height=380 src="http://stackoverflow.com" frameborder="1"></iframe>');
}
爲什麼你不使用jquery的力量而不是好的舊javascript。 – ankur 2012-07-31 10:11:34