Friday, January 2, 2009

Essential steps for cross browser compatible Javascript

Working with javascript opens up a whole set of possibilities for web developers. But at the same time, web developers have to deal with bunch of new issues when dealing with several browsers. The main reason behind this is because, each vendor has implemented the DOM in each browser differently. Some follows W3C standard while others don't. MS IE is the big bully in the block. IE usually doesn't respect W3C standards. So developers must put little extra effort from the very beginning of there development.

  1. Always use a cross browser compatible javascript library for your DOM methods.
    - YUI (http://developer.yahoo.com/yui/event/)
    - JQuery (http://jquery.com/)

  2. Separate the view of the application (HTML) from its behavior (JavaScript).

  3. Always be extra careful when dealing with dynamic event handlers.
    Ex:(YUI is used in the following example and it outlines a practice example of the above three)
    The html file (test.html)


    <html>
    <head>
    <!-- Uncomment these lines if you want to keep YUI localy
    <script type="text/javascript" src="yui/build/yahoo/yahoo-min.js"></script>
    <script type="text/javascript" src="yui/build/event/event-min.js"></script>
    <script type="text/javascript" src="yui/build/connection/connection-min.js"></script>
    -->

    <script type="text/javascript" src="http://yui.yahooapis.com/2.6.0/build/yahoo/yahoo-min.js"></script>
    <script type="text/javascript" src="http://yui.yahooapis.com/2.6.0/build/event/event-min.js"></script>
    <script type="text/javascript" src="http://yui.yahooapis.com/2.6.0/build/connection/connection-min.js"></script>

    <!-- Source File -->
    <script type="text/javascript" src="ext.js"></script>

    <script type="text/javascript">
    //when the DOM is ready execute the methord
    YAHOO.util.Event.onDOMReady(init);
    </script>
    <title>Page Title</title>
    </head>
    <body>
    <div id="messageOut" style="display:none;"></div>
    <br /><br />
    <form>
    <input type="text" id="messageIn" />
    <input type="button" id="messageButton" value="Test Me" />
    </form>
    </body>
    </html>

    ext.js

    function init(){
    YAHOO.util.Event.addListener("messageButton", "click", showMessage);
    }
    function showMessage(){

    var messageButton = document.getElementById('messageButton');
    var messageIn = document.getElementById('messageIn');
    var messageOut = document.getElementById('messageOut');
    messageOut.style.display = "";
    messageOut.innerHTML = messageIn.value;
    }

    Note:To run the above example, you only need to save the two files “test.html” and “ext.js”. The YUI library files will be picked from the online sever.

3 comments:

lee said...

I like nike air max 90 shoes ,I like to buy the cheap nike shoes by the internet shop . the puma shoes and the adidas shoes (or addidas shoes) are more on internet shop .i can buy the cheap nike shoes and cheap puma shoes online. It’s really convenient.

lee said...

I like nike air max 90 shoes ,I like to buy the cheap nike shoes by the internet shop . the puma shoes and the adidas shoes (or addidas shoes) are more on internet shop .i can buy the cheap nike shoes and cheap puma shoes online. It’s really convenient.

theprophet said...

sneakers shoes She continued,
"Why...? Don't you need someone to pose as your girlfriend this year?" Then he answered, "No, there is no need for that anymore......"
Before he can continue, Nike Tnhe was interrupted, discount nike shoes"Oh yes! Must have found a girlfriend! nike shox r4 You haven't been searching for one for the past years, right?" The man looked up, as if he has struck gold, his face beamed and looked directly at the drunken girl. tn dollarHe replied, "Yes......you are right! I haven't been looking for anyone for the past years."
With that, the man darted across the floor and out the door, cheap nike shoesleaving the lady in much bewilderment. He finally realized that he has already found his dream girl, and she was.....the Vancouver girl all along! The drunken lady has said something that awoken him.
All along he has found his girl.nike tennis shoes That was why he did not bother to look further when he realized she was not coming back. It was not any specific girl he was seeking! cheap nike shoxIt was perfection that he wanted, and yes.....perfection!!
Relationship is something both parties should work on. Realizing that he had let away someone so important in his life, he decided to call her immediately. His whole mind was flooded with fear.free shipping shoes He was afraid that she might have found someone new or no longer had the same feelings anymore..... For once, Paypal Credit card Accepthe felt the fear of losing someone.
As it was Christmas eve, the line was quite hard to get through, especially an overseas call. He tried again and again, never giving up. Finally, he got through......precisely at 1200 midnight. He confessed his love for her and the girl was moved to tears. nike shoes It seemed that she never got over him! Even after so long, she was still waiting for him, never giving up.
He was so excited to meet her and to begin his new chapter of their lives. He decided to fly to Vancouver to join her. It was the happiest time of their lives! nike discount shoes But their happy time was short-lived. Two days before he was supposed to fly to Vancouver,cheap puma shoes he received a call from her father. She had a head-on car collision with a drunken driver. nike shox shoes She passed away after 6 hours in a coma.
The guy was devastated, as it was a complete loss. Why did fate played such cruel games with him? He cursed the heaven for taking her away from him, denying even one last look at her! How cruel he cursed! chaussures nikeHow he damned the Gods...!!nike free shoes How he hated himself....for taking so long to realize his mistake!! That was in 1996.
The moral of this story is :
Treasure what you have...
Time is too slow for those who wait;
Too swift for those who fear;
Too long for those who grief;
Too short for those who rejoice;
But for those who love...
Time is Eternity.
For all you out there with someone special in your heart, cherish that person, cherish every moment that you spend together that special someone, for in life, anything can happen anytime. buy shoes onlineYou may painfully regret, only to realise that it is too late.