0

我得到以下代码:

<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 中?甚至可能吗?

4

2 回答 2

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>
于 2012-08-28T09:52:01.300 回答
1

是的,有可能。你可以这样做。

parent.document.getElementById('someid').innerHTML=pagetitle;
于 2012-08-28T09:49:11.667 回答