问题
I tried using
onPageLoad: function() {
    alert("hi");
}
but it won't work. I need it for a Firefox extension.
Any suggestions please?
回答1:
If you want to do this in vanilla javascript, just use the window.onload event handler.
window.onload = function() {
  alert('hi!');
}
回答2:
var itsloading = window.onload;
or
<body onload="doSomething();"></body> 
//this calls your javascript function doSomething
for your example
<script language="javascript">
function sayhi() 
{
  alert("hi")
}
</script>
<body onload="sayhi();"></body> 
EDIT -
For the extension in firefox On page load example
回答3:
Assuming you meant the onload-event:
You should use a javascript library like jQuery to make it work in all browsers.
<script type="text/javascript">
    $(document).ready(function() {
        alert("Hi!");
    });
</script>
If you really don't want to use a javascript library (Don't expect it to work well in all browsers.):
<script type="text/javascript">
    function sayHi() {
        alert("Hi!");
    }
</script>
<body onload="javascript:sayHi();">
...
回答4:
       <script language="javascript">
    window.onload = onPageLoad();
    function onPageLoad() {
        alert('page loaded!');
        }
</script>
来源:https://stackoverflow.com/questions/889564/how-do-you-use-onpageload-in-javascript