现在的位置: 首页 > 综合 > 正文

JavaScript 类库

2013年05月16日 ⁄ 综合 ⁄ 共 4046字 ⁄ 字号 评论关闭
1/*------------------------------------------------------------
  2 *                    S.Sams Lifexperience
  3 * CopyRight (C) 2003-2007 S.Sams Lifexperience ScriptClassLib
  4 * MSNLive: S.Sams#msn.com
  5 * Http://blog.8see.net/
  6 * UPdate by : 2007-01-19 转载传播请保留版权
  7 *-----------------------------------------------------------*/

  8 
  9
 10/*    $ 获取指定对象
 11    @element    对象名
 12    可以使用对象名集合,返回值为对象的集合
 13    如果您使用了 Prototype 类库, 请把该函数注释掉
 14    Sams_object.Get() 中同样实现该函数的所有功能
 15*/

 16function $(element) {
 17  if (arguments.length > 1{
 18    for (var i = 0, elements = [], length = arguments.length; i < length; i++)
 19      elements.push($(arguments[i]));
 20    return elements;
 21  }

 22  if (typeof element == 'string')
 23    element = document.getElementById(element);
 24  return element;
 25}

 26
 27/// 浏览器相关操作
 28var Sams_browse = {
 29    /*    检测浏览信息 */
 30    checkBrowser : function ()
 31    
 32                this.ver=navigator.appVersion 
 33                this.dom=document.getElementById?1:0 
 34                this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom)?1:0
 35                this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0
 36                this.ie4=(document.all && !this.dom)?1:0
 37                this.ns5=(this.dom && parseInt(this.ver) >= 5?1:0
 38                this.ns4=(document.layers && !this.dom)?1:0
 39                this.mac=(this.ver.indexOf('Mac') > -1?1:0
 40                this.ope=(navigator.userAgent.indexOf('Opera')>-1); 
 41                this.ie=(this.ie6 || this.ie5 || this.ie4) 
 42                this.ns=(this.ns4 || this.ns5) 
 43                this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns5 || this.ns4 || this.mac || this.ope) 
 44                this.nbw=(!this.bw) 
 45                return this;
 46    }
,
 47
 48    /*    设为首页
 49        @url        要设为首页的地址
 50    */

 51    SetDefault : function ()
 52    {
 53        this.style.behavior='url(#default#homepage)';
 54        this.setHomePage(this.GetUrl());
 55        return false;
 56    }
,
 57
 58    /*    复制指定URL地址
 59        @Msg        要写入剪贴板的字符集
 60    */

 61    SetCopy    : function (Msg){
 62        if(navigator.userAgent.toLowerCase().indexOf('ie') > -1{
 63            clipboardData.setData('Text',Msg);
 64            alert ("网址“"+Msg+"”\n已经复制到您的剪贴板中\n您可以使用Ctrl+V快捷键粘贴到需要的地方");
 65        }

 66        else 
 67        {
 68            prompt("请复制网站地址:",Msg); 
 69        }

 70    }
,
 71
 72    /*    加入收藏
 73        @site        站点名称
 74        @url        地址
 75    */

 76    AddBookmark : function (site, url){
 77        if(navigator.userAgent.toLowerCase().indexOf('ie') > -1{
 78            window.external.addFavorite(url,site)
 79        }
 else if (navigator.userAgent.toLowerCase().indexOf('opera') > -1{
 80            alert ("请使用Ctrl+T将本页加入收藏夹");
 81        }
 else {
 82            alert ("请使用Ctrl+D将本页加入收藏夹");
 83        }

 84    }
,
 85
 86    /*    打开Url指定宽度和高度的窗口 */
 87    OpenWindows : function (url,width,height)
 88    {
 89        window.open(url,'newwin','width='+width+',height='+height);
 90        return false;
 91    }
,
 92
 93    /*    禁止浏览器的Javascript错误提示 */
 94    CloseError : function(){
 95        window.onerror = function(){return true;};
 96    }
,
 97
 98    /*    获取浏览器URL */
 99    GetUrl : function(){
100        return location.href;
101    }
,
102
103    /*    获取URL参数 */
104    GetUrlParam : function(){
105        return location.search;
106    }
,
107    
108    /*    获取页面来源 */
109    GetFrom : function(){
110        return document.referrer;
111    }
,
112
113    /*    获取指定的URL参数值
114        @name        参数名
115    */

116    Request : function(name){
117        var GetUrl = this.GetUrl();
118        var Plist = new Array();
119        if(GetUrl.indexOf('?') > 0)
120        {
121            Plist = GetUrl.split('?')[1].split('&');
122        }

123        else if(GetUrl.indexOf('#') > 0)
124        {
125            Plist = GetUrl.split('#')[1].split('&');
126        }

127        if (GetUrl.length > 0)
128        {
129            for(var i=0; i<Plist.length; i++)
130

抱歉!评论已关闭.