勾一个JavaScript事件的页面加载 [英] Hook a javascript event to page load

查看:104
本文介绍了勾一个JavaScript事件的页面加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有以下JavaScript函数体的onload事件中是跑一个a​​spx。

I have an aspx that has the following javascript function being ran during the onload event of the body.

<body onload="startClock();">

不过,我设置ASPX为使用母版页,所以身体标记不在ASPX存在了。我该如何去有关注册startClock功能,当页面被击中运行,仍然有它使用一个母版?

However, I'm setting the aspx up to use a master page, so the body tag doesn't exist in the aspx anymore. How do I go about registering the startClock function to run when the page is hit and still have it use a masterpage?

推荐答案

如果你不想明确指定的window.onload或使用框架,考虑:

If you don't want to explicitly assign window.onload or use a framework, consider:

<script type="text/javascript">
function startClock(){
    //do onload work
}
if(window.addEventListener){
    window.addEventListener('load',startClock,false); //W3C
}
else{
    window.attachEvent('onload',startClock); //IE
}
</script>

<一个href=\"http://www.quirksmode.org/js/events_advanced.html\">http://www.quirksmode.org/js/events_advanced.html

这篇关于勾一个JavaScript事件的页面加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆