Current time: 09-22-2020, 09:13 PM Hello There, Guest! (LoginRegister)

Post Reply 
 
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Facebook's "like" button
06-25-2010, 07:54 AM
Post: #4
RE: Facebook's "like" button
Hey There,

I do not use that same method to defer JavaScript.

However, here are a few things you can try to do.

#1 - The first thing that comes to mind is perhaps you are assigning window.onload a function in different locations. If you do this, your previous function may get overwritten. To overcome this, I have altered a function that is commonly found on the internet:

Code:
var bodyHasLoaded=0;

function addLoadEvent(func)
{
    if(bodyHasLoaded==1)
    {
        func();
    }
    else
    {
        var oldonload=window.onload;

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

In each of my window.onload functions I set bodyHasLoaded=1. This way if an addLoadEvent call occurs after the body has loaded, it will fire right away. Otherwise, it will wait until the onload event occurs.

The original JavaScript function can be found here:
http://simonwillison.net/2004/May/26/addLoadEvent/

#2 - You could also download the JavaScript file asynchronously. Here is a little bit of code out of my common library you can use:

Code:
var protoaculousHasLoaded=0;
var myDirectory2="http://cdn.green-watch.org";

function GetXmlHttpObject(handler)
{
    var objXMLHttp=null;
    
    if(window.XMLHttpRequest)
    {    
        objXMLHttp=new XMLHttpRequest()
    }
    else if(window.ActiveXObject)
    {
        objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    
    return objXMLHttp;
}

function importProtoaculousJS(onLoadFunction)
{
    var headID=document.getElementsByTagName("head")[0];
    var protoaculousNode=document.createElement('script');
    protoaculousNode.type='text/javascript';
    
    protoaculousNode.onload=function()
    {
        protoaculousHasLoaded=1;
        
        if(onLoadFunction!='null')
        {
            onLoadFunction();
        }
    };
    
    protoaculousNode.onreadystatechange=function()
    {
        if(protoaculousNode.readyState=='complete'||protoaculousNode.readyState=='l​oaded')
        {
            protoaculousHasLoaded=1;
            
            if(onLoadFunction!='null')
            {
                onLoadFunction();
            }
        }
    };
    
    protoaculousNode.src=myDirectory2 +'/javascript/protoaculous.cfm';
    headID.appendChild(protoaculousNode);
}

Just make sure you set your paths correctly. Hope this helps.

Sincerely,
Travis Walters
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Facebook's "like" button - jarrod1937 - 06-25-2010, 04:57 AM
RE: Facebook's "like" button - jarrod1937 - 06-25-2010, 06:50 AM
RE: Facebook's "like" button - green-watch.org - 06-25-2010 07:54 AM
RE: Facebook's "like" button - jarrod1937 - 06-25-2010, 07:58 AM
RE: Facebook's "like" button - jarrod1937 - 06-26-2010, 12:37 AM
RE: Facebook's "like" button - sajal - 06-29-2010, 05:41 AM
RE: Facebook's "like" button - sajal - 06-29-2010, 06:25 AM

Forum Jump:


User(s) browsing this thread: 1 Guest(s)