JavaScript 实用方法库

/*
/* JavaScript Document
*/


/* Calculate the length of character string */
String.prototype.len
=function()
{
    
return this.replace(/[^x00-xff]/g, "**").length;
}


/* Take out the blank both on left and right */
String.prototype.trim
=function()
{
    
return this.replace(/(^[\s+| +])|([\s+| +]$)/g,"");
}


/* Take out the left blank */
String.prototype.ltrim 
= function()
{
    
return this.replace(/(^[\s+| +])/g, "");
}


/* Take out the right blank */
String.prototype.rtrim 
= function()
{
    
return this.replace(/([\s+| +]$)/g, "");
}


/* Take out left and right blank and replace multi-blank by one blank */
String.prototype.atrim 
= function() 

    
return this.replace(/(^[\s+| +])|([\s+| +]$)/g,"").replace(/\s+| +/g," ");
}

    
/* Getting the version of browser 1-IE, 2-Firefox */ 
function getOs()
{
    
if(navigator.userAgent.indexOf("MSIE")>0)return 1;
    
if(isFirefox=navigator.userAgent.indexOf("Firefox")>0)return 2;
    
return 0;
}

function RedirectLanguage(language)
        
{
            
var urlValue=window.location.href;
            
var returnURL=urlValue;
            
var indexOfQuestionMark=urlValue.indexOf("?");
            
if(indexOfQuestionMark>0)
            
{
                
var arrayUrl=urlValue.split('?');
                
var arrayParameter=arrayUrl[1].split('&');
                
var indexOfLang=arrayParameter[0].indexOf("Lang");
                
if(indexOfLang==0)
                
{
                    returnURL
=urlValue.replace(arrayParameter[0],"Lang="+language);
                }

                
else
                
{
                    returnURL
=arrayUrl[0]+"?Lang="+language+"&"+arrayUrl[1];
                }

            }

            
else
            
{
                returnURL
=urlValue.replace(/(\/+$)/g, "")+"?Lang="+language;
            }

            window.location.href
=returnURL; 
        }

posted on 2008-01-28 14:56  散步的蠕虫  阅读(228)  评论(0编辑  收藏  举报

导航