Wednesday 24 August 2011

How to make XML parsing compatible with IE

Internet Explorer is annoying as usual about this and you need to make exceptions for it.  Here's what you can do:

type: 'GET',
                        url: 'photos.xml',
                        dataType: ($.browser.msie) ? "text" : "xml", //if Browser is internet explorer, the datatype is text, otherwise xml.
                        success: getXML,
                        complete:


And then in my "success" function, add this:

if ($.browser.msie) {
    var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
    xmlDoc.loadXML(xml);
    xml = xmlDoc;
}

Thursday 18 August 2011

How to preload images??

Every find need to pre-load images to add some grace in the way your site load or to make some bon-bon effects? I bet you do.  So, let see how one can achieve it using javascript orjquery. :)


Some variables to be used to preload image
imgSrc: /path/to/chantu.jpg
 #imgBox : element where to load

Javascript Way:
//create a new image element
var imgPreload = new Image();
//attach image
imgPreload.src = imgSrc;
//now load it and when image loads, bring it inside the DOM and place it inside the #imgBox ;)
imgPreload.onload= function(){
    //place it inside the DOM
$("#imgBox").append("imgPreload");
}