I tried using
onPageLoad: function() {
alert("hi");
}
but it won't work. I need it for a Firefox extension.
Any suggestions please?
I tried using
onPageLoad: function() {
alert("hi");
}
but it won't work. I need it for a Firefox extension.
Any suggestions please?
如果你想在 vanilla javascript 中执行此操作,只需使用window.onload
事件处理程序。
window.onload = function() {
alert('hi!');
}
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
假设您的意思是 onload-event:
您应该使用jQuery之类的 javascript 库来使其在所有浏览器中都能正常工作。
<script type="text/javascript">
$(document).ready(function() {
alert("Hi!");
});
</script>
如果您真的不想使用 javascript 库(不要期望它在所有浏览器中都能正常工作。):
<script type="text/javascript">
function sayHi() {
alert("Hi!");
}
</script>
<body onload="javascript:sayHi();">
...
<script language="javascript">
window.onload = onPageLoad();
function onPageLoad() {
alert('page loaded!');
}
</script>