I tried using
我试过用
onPageLoad: function() {
alert("hi");
}
but it won't work. I need it for a Firefox extension.
但它不会起作用。我需要它用于Firefox扩展。
Any suggestions please?
有什么建议吗?
5 个解决方案
#1
If you want to do this in vanilla javascript, just use the window.onload
event handler.
如果你想在vanilla javascript中这样做,只需使用window.onload事件处理程序。
window.onload = function() {
alert('hi!');
}
#2
Assuming you meant the onload-event:
假设你的意思是onload-event:
You should use a javascript library like jQuery to make it work in all browsers.
您应该使用像jQuery这样的javascript库,使其适用于所有浏览器。
<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.):
如果你真的不想使用javascript库(不要指望它在所有浏览器中都能正常工作。):
<script type="text/javascript">
function sayHi() {
alert("Hi!");
}
</script>
<body onload="javascript:sayHi();">
...
#3
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
对于firefox中的扩展页面加载示例
#5
<script language="javascript">
window.onload = onPageLoad();
function onPageLoad() {
alert('page loaded!');
}
</script>
#1
If you want to do this in vanilla javascript, just use the window.onload
event handler.
如果你想在vanilla javascript中这样做,只需使用window.onload事件处理程序。
window.onload = function() {
alert('hi!');
}
#2
Assuming you meant the onload-event:
假设你的意思是onload-event:
You should use a javascript library like jQuery to make it work in all browsers.
您应该使用像jQuery这样的javascript库,使其适用于所有浏览器。
<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.):
如果你真的不想使用javascript库(不要指望它在所有浏览器中都能正常工作。):
<script type="text/javascript">
function sayHi() {
alert("Hi!");
}
</script>
<body onload="javascript:sayHi();">
...
#3
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
对于firefox中的扩展页面加载示例
#4
#5
<script language="javascript">
window.onload = onPageLoad();
function onPageLoad() {
alert('page loaded!');
}
</script>