简体   繁体   English

是浏览器满载检查

[英]Is browser fully loaded check

无论如何都要检查页面是否已满载。这样的内容如http://msdn.microsoft.com/en-us/library/system.web.ui.page.loadcomplete.aspx但是对于JAVA。

If you intend to execute logic on the client side when the page is loaded, you might be interested in the Javascript onload event. 如果您打算在加载页面时在客户端执行逻辑,您可能会对Javascript onload事件感兴趣。

Or, even better, consider using jQuery and use the ready() function to execute your logic. 或者,更好的是,考虑使用jQuery并使用ready()函数来执行您的逻辑。

Just a short example using jQuery: 只是一个使用jQuery的简短示例:

$(document).ready(function() {
    alert("The document, including all assets such as images, has been completely received");
});

1. JQuery will help you: 1.JQuery将帮助您:

there is $(document).ready() which tell you that the browser is loaded. $(document).ready()告诉你浏览器已加载。
Example: 例:

$(document).ready(function(){
  $("button").click(function(){
    $("p").slideToggle();
  });
});

The ready event occurs when the DOM (document object model) has been loaded, and the page has been fully loaded (including images). 当已加载DOM(文档对象模型)并且页面已完全加载(包括图像)时,就会发生就绪事件。
Because this event occurs after the document is ready, it is a good place to have all other jQuery events and functions. 因为此事件发生在文档准备好之后,所以它是获取所有其他jQuery事件和函数的好地方。 Like in the example above. 就像上面的例子一样。

2.Window onload is another JavaScript approach: 2.Window onload是另一种JavaScript方法:

window.onload=function(){SomeJavaScriptCode};

The onload event occurs when an object has been loaded. 加载对象时发生onload事件。
onload is most often used within the element to execute a script once a web page has completely loaded all content (including images, script files, CSS files, etc.). 一旦网页完全加载了所有内容(包括图像,脚本文件,CSS文件等),onload通常在元素中用于执行脚本。

Note: The main difference is that document.ready() event gets called as soon as your DOM is loaded. 注意:主要区别在于,只要加载DOM,就会调用document.ready()事件。 It does not wait for the contents to get loaded fully, while window.onload will wait until all your contents are loaded fully. 它不会等待内容完全加载,而window.onload将等待所有内容完全加载。
We can have more than one document.ready() function in a page where we can have only one onload function. 我们可以在一个只有一个onload函数的页面中有多个document.ready()函数。

you can use the normal onload() 你可以使用普通的onload()

<body onload="yourFunctionHere()">

or the JQuery version 或者JQuery版本

$(document).ready(function() {
  yourFunctionHere();
});

Not directly in java, since it is probably not running in the browser, but you can do it with javascript 不是直接在java中,因为它可能没有在浏览器中运行,但你可以用javascript来完成

 <html>
    <head>
    <title>Test Page</title>
    <script type="text/javascript">var myFunc = function() {
      alert("The page is fully loaded!");
    };
    window.onload = myFunc;
    </script>
  </head>

Not in Java, no. 不是Java,没有。 You'll need Javascript: 你需要Javascript:

<script>  
  window.onload = function() {  
    alert('Loading Complete!');  
  }
</script>  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM