title: how can I trigger an onload from a script included in a jquery plugin?
body: <p>I'm writing a jquery plugin. I have a script tag that's dynamically added for LivePerson.com. The script, once loaded, is supposed to trigger and onLoad function defined in the config. However this never fires. I'm curious if its a problem with timing maybe, since the plugin is initiated on doc ready and the script is added when the window loads? Any ideas?</p>
  
  <pre><code>jQuery(function(){
  jQuery(document).easyChat({
      popup: false,
      siteId:'XXXXXXXXX',
      appKey: 'XXXXXXXXX'
  });
  });
  </code></pre>
  
  <p>Plugin Script:</p>
  
  <pre><code>;(function($, document, window, undefined) {
  // Optional, but considered best practice by some
  "use strict";
  
  // Name the plugin so it's only in one place
  var pluginName = 'easyChat';
  var lpc;
  
  // Default options for the plugin as a simple object
  var defaults = {
      popup : true,
      skill: 'Test'
  };
  
  // Plugin constructor
  // This is the boilerplate to set up the plugin to keep our actual logic in one place
  function Plugin(element, options) {
      this.element = element;
  
      // Merge the options given by the user with the defaults
      this.options = $.extend({}, defaults, options)
  
      // Initialization code to get the ball rolling
      // If your plugin is simple, this may not be necessary and
      // you could place your implementation here
      if(this.options.popup != true){
          this.init();
      } else {
          this.popup();
      }
  }
  
  Plugin.prototype = {
      // Public functions accessible to users
      // Prototype methods are shared across all elements
      // You have access to this.options and this.element
  
      popup:function(){
          console.log("popup");
      },
  
      DoAChat:function(){
          lpc = new lpChat();
          lpc.chatAvailability(); 
  
          // alert('Before');
        //  lpc.requestChat();
          // alert('After');
          if(this.options.popup == true){
  
          } else {
          //  document.getElementById('status').innerHTML += ' Done!';
          }
      },
  
      myOnLoad:function() {
           console.log("LP JS API Initiated");
          this.DoAChat();
      },
  
      myOnInit:function() {
  
      },
  
      myOnStart:function() {
  
      },
  
      myOnStop:function() {
  
      },
  
      myOnState:function() {
  
      },
  
      myOnTyping:function() {
  
      },
  
      myOnPush:function() {
  
      },
  
      myOnLine:function() {
  
      },
  
      myOnError:function() {
  
      },
  
      myOnAvailability:function(availObj) {
      console.log(availObj);
      },
  
      myOnResume:function() {
  
      },
  
      myOnAccountToAccountTransfer:function() {
  
      },
  
      //First Method triggered from plugin init
      init: function() {
         var lpChatConfig = {
          apiKey : this.options.appKey,lpNumber : this.options.siteId,  
          lpServer: 'dev.liveperson.net',
          onLoad : this.myOnLoad,  
          onInit : this.myOnInit,
          onStart : this.myOnStart,  
          onStop : this.myOnStop,
          onState : this.myOnState,  
          onAgentTyping : this.myOnTyping,
          onUrlPush : this.myOnPush,  
          onLine : this.myOnLine,
          onError : this.myOnError,  
          onAvailability: this.myOnAvailability,
          onResume : this.myOnResume,  
          onAccountToAccountTransfer: this.myOnAccountToAccountTransfer,
          skill: this.options.skill
          };
  
          lpChatConfig.lpAddScript = function(src, ignore) {var c = lpChatConfig;if(typeof(c.lpProtocol)=='undefined'){c.lpProtocol = (document.location.toString().indexOf("https:")==0) ? "https" : "http";}if (typeof(src) == 'undefined' || typeof(src) == 'object') {src = c.lpChatSrc ? c.lpChatSrc : '/hcp/html/lpChatAPI.js';};if (src.indexOf('http') != 0) {src = c.lpProtocol + "://" + c.lpServer + src + '?site=' + c.lpNumber;} else {if (src.indexOf('site=') &lt; 0) {if (src.indexOf('?') &lt; 0)src = src + '?'; else src = src + '&amp;';src = src + 'site=' + c.lpNumber;}};var s = document.createElement('script');s.setAttribute('type', 'text/javascript');s.setAttribute('charset', 'iso-8859-1');s.setAttribute('src', src);document.getElementsByTagName('head').item(0).appendChild(s);}
  if (window.attachEvent) window.attachEvent('onload', lpChatConfig.lpAddScript);
  else window.addEventListener('load', lpChatConfig.lpAddScript, false);
  
  
  
  
  
      }
  
  
  
  };
  
  $.fn[pluginName] = function(options) {
      // Iterate through each DOM element and return it
      return this.each(function() {
          // prevent multiple instantiations
          if (!$.data(this, 'plugin_' + pluginName)) {
              $.data(this, 'plugin_' + pluginName, new Plugin(this, options));
          }
      });
  };
  
  // Private function that is only called by the plugin
  var privateFunction = function() {
      // ...
  }
  
  })(jQuery, document, window);
  </code></pre>