WordPress.org

Ready to get started?Download WordPress

Forums

What is the right way to add an onload function? (1 post)

  1. SocialBlogsite
    Member
    Posted 2 years ago #

    It seems my onload is replaced by wordpres's.

    I'm adding javascript in the header (not a link) from a plugin.

    I tried the following no success:

    function addLoadEvent(func) {
      var oldonload = window.onload;
      if (typeof window.onload != 'function') {
        window.onload = func;
      } else {
        window.onload = function() {
          if (oldonload) {
            oldonload();
          }
          func();
        }
      }
    }
    addLoadEvent(function() {
      /* my code here */
    });

    Is there an official way to do it?

Topic Closed

This topic has been closed to new replies.

About this Topic

  • RSS feed for this topic
  • Started 2 years ago by SocialBlogsite
  • This topic is not resolved
  • WordPress version: 3.3.1