JavaScript implements a method that executes a specified function when a Web page is loaded _javascript tips

Source: Internet
Author: User

This article describes the JavaScript implementation method that executes the specified function when the Web page is loaded. Share to everyone for your reference. The specific analysis is as follows:

The following JS code demonstrates how to call a specified function when a Web page is loaded, and you can add multiple functions dynamically at the same time through the second segment of code.

All we need to do is assign a function to Window.onload to perform the Mycoolinitfunc function automatically when the page load completes

<script type= "Text/javascript" >
  window.onload = Mycoolinitfunc
</script>

If you want to execute more than one function in parallel after the page is loaded, you can implement it by using the following JS code

function Addloadevent (func) {
  var oldonload = window.onload;
  if (typeof window.onload!= ' function ') {
    window.onload = func;
  }
  else {
    window.onload = function () {
      oldonload ();
      Func ();}}

I hope this article will help you with your JavaScript programming.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.