Chrome扩展程序:window.onload不起作用

时间:2014-04-20 22:05:52

标签: javascript google-chrome-extension

当我加载独立于扩展名的html文件时,此代码有效(在另一个文件中...我已经复制并粘贴了相关的部分,但由于某种原因它不起作用这个文件)。无论如何,当我尝试在原始扩展中运行此部分时,除了数值之外,我得到了所有内容。发生了什么事?

popup.html文件:

<html>
<header>
<script type="text/javascript" src="Kill_Count.js"></script> 
</header>
<body>
<table>

  <td width="300">
  Stuff About Animals...
  </td>    
  <td>

      <table cellpadding="0" cellspacing="0">        

      <tr>
         <td>Pigs</td>
         <td align="right">
         <scpan id="Kill_Count"></span>
         <script type="text/javascript">window.onload = Kill_Count('Kill_Count');</script>
        </td>
      </tr>
      </table>

  </td> 
</table>
</body>
</html>

Kill_Count.js文件:

function Kill_Count(id)
{
  var animal = "Pigs";
  var totalDeaths = 1375940758;
  var deathsPerSecond = totalDeaths/365/24/60/60/4;
  var deaths = 0;
  var timer = 1;
  setInterval(function() {    
     deaths = deathsPerSecond*timer;     
     result = deaths.toFixed();
     document.getElementById(id).innerHTML = result;
     timer++;
  }, 250);
}

0 个答案:

没有答案