如何检测网页何时加载? [英] How do I detect when a web page is loaded?

查看:81
本文介绍了如何检测网页何时加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写一个应用程序来检测浏览器何时加载页面,然后我应该能够在加载的网页上插入内容?任何人有想法如何做到这一点?



请注意,我应该能够在任何浏览器(Firefox / IE)中执行此操作。



我应该用什么语言来帮助我做到这一点?



如何从外部应用程序中检测到这一点?



我应该如何将它与浏览器整合?

您会使用javascript来做这个。如果你不知道如何使用javascript,我会建议阅读一些 教程 来检测页面何时加载。您可以使用 window.onload 事件。

  window.onload = function(){
addPageContents( ); //示例函数调用。

$ / code>

编辑:如果你想添加多个onload函数,而不是使用一个JavaScript库,你可以打包自己的onload hanlder。

  window.whenloaded = function(fn){
if (window.onload){
var old = window.onload;
window.onload = function(){
old();
fn();
}
} else {
window.onload = fn;
}
}


I want to write an application that detects when a page is loaded in the browser, then I should be able to insert content on top of the loaded web page? Anybody with an idea on how to do that?

Please note that I should be able to do this in any browser (Firefox/IE).

What language should I use to help me do this?

How do I detect this from an external application?

How should I integrate this with the browser?

解决方案

You would use javascript to do this. If you don't know how to use javascript, I would recommend reading through some tutorials first.

After you have a basic understanding of javascript, you can detect when a page has loaded by using the window.onload event.

window.onload = function() {
  addPageContents();  //example function call.
}

Edit: If you want to add more than one onload function, and not use a javascript library, you can wrap your own onload hanlder.

window.whenloaded = function(fn) {
  if (window.onload) {
    var old = window.onload;
    window.onload = function() {
      old();
      fn();
    }
  } else {
    window.onload = fn;
  }
}

这篇关于如何检测网页何时加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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