Tuesday 21 August 2012

Javascript after page DOM is loaded

How many times you want to execute a java script method after page components have been loaded completely and page view is not displayed till now.

So, here is the java script code for the problem:

<script type="text/javascript" language="javascript">
    if(window.onload) {
        var curronload = window.onload;
        var newonload = function() {
            curronload();
            yourFunctionName();
        };
        window.onload = newonload;
    } else {
        window.onload = yourFunctionName;
    }
   
    yourFunctionName = function() {
        console.log( document.getElementById('AnyHTMLComponentId') );
    }
</script>

This works great for me and hope for you also.

Enjoy....

No comments:

Post a Comment