Tuesday, November 23, 2010

Emulate IE7

Every time browsers upgrade their version, programmer also will face headache on the application compatibility. I got one application that run on IE7 but somehow some customer complained that it won't work on their browser which is IE8.

But I found solution , so I posted it here so I don't have to Google every time I forget.

<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />

Put the code inside inside head tag like below:

<head><meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" /></head>

I got this from  Introducing IE=EmulateIE7 .Not sure what happen if they upgrade to version 9, but for time being just enjoy.

Tuesday, October 19, 2010

XSLT Transformation using JQuery

A few weeks ago, I was facing this problem - HTML is not rendering in Chrome and Safari while it works perfectly in Firefox and IE.

After did some study and some try and errors at last I got the solution. Using JQuery Transform plugin .But still need to do some changes.

Once you downloaded it, open jquery.transform.js. Replace the var safariimportincludefix = function(xObj,rootConfig){} with

var safariimportincludefix = function(xObj,rootConfig) {
    var vals = $.merge($.makeArray(xObj.getElementsByTagName("import")),$.makeArray(xObj.getElementsByTagName("include")));

    for(var x=0;x<vals.length;x++) {
        var node = vals[x];
            passData : { node : node, xObj : xObj, rootConfig : rootConfig},
            dataType : "xml",
            async : false,
            url : replaceref(node.getAttribute("href"),rootConfig),
            success : function(xhr) {
                try {
                    var _ = this.passData;
                    xhr = safariimportincludefix(xhr,_.rootConfig);

                    var imports = $.merge(childNodes(xhr.getElementsByTagName("stylesheet")[0],"param"),childNodes(xhr.getElementsByTagName("stylesheet")[0],"template"));
                    var excistingNodes = [];
                        var sheet = _.xObj;
                        var params = childNodes(sheet,"param");
                        var stylesheets = childNodes(sheet,"template");
                        existingNodes = $.merge(params,stylesheets);
                        var x = exception;
                    var existingNames = [];
                    var existingMatches = [];
                    for(var a=0;a&lt;existingNodes.length;a++) {
                        if(existingNodes[a].getAttribute("name")) {
                            existingNames[existingNodes[a].getAttribute("name")] = true;
                        } else {
                            existingMatches[existingNodes[a].getAttribute("match")] = true;

                    var pn = _.node.parentNode;
                    for(var y=0;y&lt;imports.length;y++) {
                        if(!existingNames[imports[y].getAttribute("name")] &amp;&amp; !existingMatches[imports[y].getAttribute("match")]) {
                            var clonednode = _.xObj.ownerDocument.importNode(imports[y],true);
                } catch(ex) { 


    return xObj;

Then just call the script from your html header. Below some codes that show how to execute it.

Snippet  that demonstrates how to call jquery

  var animalElementArray =  response.getElementsByTagName("animal");
     var animalTable = dojo.byId("animal");
     var tbodyArray=animalTable.getElementsByTagName("tbody");
    if (animalTable != null){
        if (animalTable.getElementsByTagName("tbody")[0] != null){
        var tbodysArray = animalTable.getElementsByTagName("tbody");
            for(p=0;p&lt; tbodysArray.length;p++){
    var newtbody;
    if (animalTable.getElementsByTagName("tbody").length==0)  
        newtbody = document.createElement('tbody');
     else {

 if(dojo.isChrome || dojo.isSafari){
                 try  {        
                 resultDocument= $.transform({el:"resultDocument",async:false, xmlobj: response.documentElement, xslobj:  xsl,xslParams:{name:"cat",type:"mammal"}});
                 var tbody = resultDocument;
                 var animalTableParent = animalTable.parentNode;
                 animalTableParent.innerHTML = tbody;
                 catch (exception) 
                     if (typeof (exception) == "object" &amp;&amp; exception.message) 
                     else alert(exception);

Loading function.

function loadXMLDoc(file) {
        var xmlDoc;
        // code for IE
        if (window.ActiveXObject) {
          xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
        // code for Mozilla, Firefox, Opera, etc.
        else if (document.implementation &amp;&amp; document.implementation.createDocument) {
            var xmlhttp = new window.XMLHttpRequest();
            var xmlDoc = xmlhttp.responseXML.documentElement;          
        } else {
          alert('Your browser cannot handle this script');
Of course I got it from Internet. You can google, but the fastest way you can refer here :



Friday, July 02, 2010

Display special character

I have problem when user key in single quote or double quote in textfield and view it in textfield. I am using jsp where by I put the code like this

user input >>

display output >>

It saved successfully in Oracle database , but problem happen when it want to display in input field.

Then I change my code into

Yes, it save a day but only for awhile because the user might be key in input such

user input >>

display output >>

See, it cannot read the double quote because it stop at double quote.

At last this morning, I found out the solution.
public String convSpecialChar(String htmlString)
   htmlString = htmlString.replaceAll("\\&lt;.*?\\&gt;", "");
  htmlString = htmlString.replaceAll("\r", "
  htmlString = htmlString.replaceAll("\n", "
  htmlString = htmlString.replaceAll("\"",""");
  htmlString = htmlString.replaceAll("\'","'");
  htmlString = htmlString.replaceAll(",",",");
   return htmlString;
So I called it like below :

So I have no problem with double quote,single quote and maybe some other special character. I think maybe there other way effective way to do this but somehow this code save me for a while