几个关于HTML的js方法

  1. //加入收藏  
  2. function addBookmark(title) {  
  3.      var url=parent.location.href;  
  4.      if (window.sidebar) {   
  5.             window.sidebar.addPanel(title, url,"");   
  6.      } else if( document.all ) {  
  7.         window.external.AddFavorite( url, title);  
  8.      } else if( window.opera && window.print ) {  
  9.         return true;  
  10.      }  
  11. }  
  12. //设置首页  
  13. function setHome(obj,vrl){  
  14.     try{  
  15.         obj.style.behavior='url(#default#homepage)';obj.setHomePage(vrl);  
  16.     } catch(e){  
  17.         if(window.netscape) {  
  18.                 try {  
  19.                     netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");    
  20.                 } catch (e)  {   
  21.                     alert("抱歉!您的浏览器不支持直接设为首页。请在浏览器地址栏输入“about:config”并回车然后将[signed.applets.codebase_principal_support]设置为“true”,点击“加入收藏”后忽略安全提示,即可设置成功。");    
  22.                 }  
  23.                 var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);  
  24.                 prefs.setCharPref('browser.startup.homepage',vrl);  
  25.          }  
  26.     }  
  27. }  
  28.   
  29. var MY=new Object();   
  30. //Cookie读取函数  
  31. MY.Cookie = {  
  32.     set:function(name,value,expires,path,domain) {  
  33.         if(typeof expires=="undefined") {  
  34.             expires=new Date(new Date().getTime()+24*3600*1000);  
  35.         }  
  36.         document.cookie=name+"="+decodeURI(value)+((expires)?"; expires="+expires.toGMTString():"")+((path)?"; path="+path:"; path=/")+((domain)?";domain="+domain:"");  
  37.     },  
  38.     get:function(name) {  
  39.         var arr=document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));  
  40.         if(arr!=null) {  
  41.             return decodeURIComponent(arr[2]);  
  42.         }  
  43.         return null;  
  44.     },  
  45.     clear:function(name,path,domain) {  
  46.         if(this.get(name)) {  
  47.             document.cookie=name+"="+((path)?"; path="+path:"; path=/")+((domain)?"; domain="+domain:"")+";expires=Fri, 02-Jan-1970 00:00:00 GMT";  
  48.         }  
  49.     }  
  50. };   
  51.   
  52. //限制图片尺寸  
  53. function limitImage(ImgD, areaWidth, areaHeight){     
  54.      var flag=false;  
  55.      if (!areaWidth) {  
  56.         areaWidth = 600;  //图片区域的宽度。   
  57.      }  
  58.      if (!areaWidth) {  
  59.         areaHeight = 450; //图片区域的高度。    
  60.      }  
  61.      var image = new Image();  
  62.      try {  
  63.          image.src = ImgD.src;     
  64.          if(image.width>0 && image.height>0){     
  65.              flag=true;     
  66.              if(image.width/image.height>= areaWidth/areaHeight){     
  67.                  if(image.width>areaWidth) {     
  68.                     ImgD.width=areaWidth;     
  69.                      ImgD.height=(image.height*areaWidth)/image.width;     
  70.                  } else {     
  71.                      ImgD.width=image.width;     
  72.                      ImgD.height=image.height;     
  73.                  }  
  74.              } else {     
  75.                  if(image.height>areaHeight){     
  76.                      ImgD.height=areaHeight;     
  77.                      ImgD.width=(image.width*areaHeight)/image.height;     
  78.                  } else {     
  79.                      ImgD.width=image.width;     
  80.                      ImgD.height=image.height;     
  81.                  }  
  82.              }     
  83.          }    
  84.      } catch (e) {  
  85.         //nothing  
  86.      }  
  87.  }  
  88.    
  89. //带参数的 复制到剪切板  
  90. function copyCodes(ele){  
  91.     if(copy2Clipboard(ele)!=false){   
  92.         alert("生成的代码已经复制到粘贴板,你可以使用Ctrl+V 贴到需要的地方去了哦! ");   
  93.     }   
  94. }  
  95.    
  96.   
  97. //复制到剪切板  
  98. function copyCode(){  
  99.     var testCode = "";  
  100.     testCode += document.title + '  ' + this.location.href;   
  101.     if(copy2Clipboard(testCode)!=false){   
  102.         alert("生成的代码已经复制到粘贴板,你可以使用Ctrl+V 贴到需要的地方去了哦! ");   
  103.     }   
  104. }   
  105. copy2Clipboard=function(txt){   
  106.     if(window.clipboardData){   
  107.         window.clipboardData.clearData();   
  108.         window.clipboardData.setData("Text",txt);   
  109.     }   
  110.     else if(navigator.userAgent.indexOf("Opera")!=-1){   
  111.         window.location=txt;   
  112.     }   
  113.     else if(window.netscape){   
  114.         try{   
  115.             netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");   
  116.         }   
  117.         catch(e){   
  118.             alert("您的firefox安全限制限制您进行剪贴板操作,请打开'about:config'将signed.applets.codebase_principal_support'设置为true'之后重试,相对路径为firefox根目录/greprefs/all.js");   
  119.             return false;   
  120.         }   
  121.         var clip=Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);   
  122.         if(!clip)return;   
  123.         var trans=Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);   
  124.         if(!trans)return;   
  125.         trans.addDataFlavor('text/unicode');   
  126.         var str=new Object();   
  127.         var len=new Object();   
  128.         var str=Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);   
  129.         var copytext=txt;str.data=copytext;   
  130.         trans.setTransferData("text/unicode",str,copytext.length*2);   
  131.         var clipid=Components.interfaces.nsIClipboard;   
  132.         if(!clip)return false;   
  133.         clip.setData(trans,null,clipid.kGlobalClipboard);   
  134.     }   
  135. }  
  136.   
  137. /** 
  138.  * 获取url地址参数 
  139.  */  
  140. function getUrlParam(paramName) {  
  141.     var returnVal="";  
  142.     try{  
  143.         var paramUrl=window.location.search;  
  144.         //处理长度  
  145.         if (paramUrl.length>0) {  
  146.             paramUrl = paramUrl.substring(1, paramUrl.length);  
  147.             var paramUrlArray = paramUrl.split("&");  
  148.             for (var i=0; i<paramUrlArray.length; i++) {  
  149.                 if (paramUrlArray[i].toLowerCase().indexOf(paramName.toLowerCase())!=-1) {  
  150.                     var temp=paramUrlArray[i].split("=");  
  151.                     if(temp[0].toLowerCase()==paramName.toLowerCase()) {  
  152.                         returnVal=temp[1];  
  153.                         break;  
  154.                     }  
  155.                 }  
  156.             }  
  157.         }  
  158.         returnVal = decodeURIComponent(returnVal);  
  159.     } catch(e) {  
  160.         //nothing  
  161.     };  
  162.     return returnVal;  
  163. }  
  164.   
  165. //渠道来源记录  
  166. try {  
  167.     if (getUrlParam('utm_source')!="" && getUrlParam('utm_medium')!="") {  
  168.         MY.Cookie.set('utm_tag', getUrlParam('utm_source') + '|' + getUrlParam('utm_medium') + '|' + getUrlParam('utm_place'), new Date(new Date().getTime()+1*24*3600*1000), '/''game.10086.cn');  
  169.     }  
  170. catch(e) {  
  171.     //nothing  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值