我收到了以下代码:
<body>
<div class="header">
<div class="logo">
title of page goes here
</div>
</div>
<iframe src='sameserver.html'>
<script>
var pagetitle = 'page title';
</script>
</iframe>
</body>
现在我怎样才能将javascript var放在logo div中? 它甚至可能吗?
答案 0 :(得分:3)
广告ID
到您的徽标,等待iFrame
加载并将变量放到#logo
<body>
<div class="header">
<div class="logo" id="logo">
title of page goes here
</div>
</div>
<iframe src="sameserver.html" name="myIFrame"></iframe>
<script type="text/javascript">
window.myIFrame.onload = function (){
title = window.myIFrame.pagetitle;
document.getElementById('logo').innerHTML = title;
}
</script>
</body>
和sameserver.html
:
<script>
var pagetitle = 'page title';
</script>
答案 1 :(得分:1)
parent.document.getElementById('someid').innerHTML=pagetitle;