javascript 应用小技巧方法汇总(5)

<iframe src="https://www.jb51.net/article/a.html" scrolling="no" frameborder=0 marginwidth=0 marginheight=0></iframe> <script> var doc=window.frames["f"].document; function s(){ if (doc.readyState=="complete"){ document.all.f.style.height=doc.body.scrollHeight document.all.f.style.width=doc.body.scrollWidth } } doc.onreadystatechange=s </script>

//刷新后不变的文本框

<HTML> <HEAD> <META CONTENT="history"> <STYLE> .sHistory {behavior:url(#default#savehistory);} </STYLE> </HEAD> <BODY> <INPUT type=text id=oPersistInput> </BODY> </HTML>

//访问剪贴板

(1)拖拽访问

event.dataTransfer.setData("URL", oImage.src); sImageURL = event.dataTransfer.getData("URL") (2)普通访问 window.clipboardData.setData("Text",oSource.innerText); window.clipboardData.getData("Text");

//操作COOKIE

function SetCookie(sName, sValue) { document.cookie = sName + "=" + escape(sValue) + "; "; } function GetCookie(sName) { var aCookie = document.cookie.split("; "); for (var i=0; i < aCookie.length; i++) { var aCrumb = aCookie[i].split("="); if (sName == aCrumb[0]) return unescape(aCrumb[1]); } } function DelCookie(sName) { document.cookie = sName + "=" + escape(sValue) + "; expires=Fri, 31 Dec 1999 23:59:59 GMT;"; }

//setTimeout增加参数

复制代码 代码如下:

<script>
var _st = window.setTimeout;
window.setTimeout = function(fRef, mDelay) { if(typeof fRef == 'function'){   var argu = Array.prototype.slice.call(arguments,2);
  var f = (function(){ fRef.apply(null, argu); });   return _st(f, mDelay); } return _st(fRef,mDelay); } function test(x){ alert(x); }
window.setTimeout(test,1000,'fason'); </script>


//自定义的apply,call

复制代码 代码如下:

Function.prototype.apply = function (obj, argu) { if (obj) obj.constructor.prototype._caller = this;  var argus = new Array();
for (var i=0;i<argu.length;i++)
  argus[i] = "argu[" + i + "]"; var r; eval("r = " + (obj ? ("obj._caller(" + argus.join(",") + ");") : ("this(" + argus.join(",") + ");"))); return r; };
Function.prototype.call = function (obj) { var argu = new Array();
for (var i=1;i<arguments.length;i++)
  argu[i-1] = arguments[i]; return this.apply(obj, argu); }; 

//下载文件

复制代码 代码如下:

function DownURL(strRemoteURL,strLocalURL) {
try {   var xmlHTTP=new ActiveXObject("Microsoft.XMLHTTP");   xmlHTTP.open("Get",strRemoteURL,false);   xmlHTTP.send();   var adodbStream=new ActiveXObject("ADODB.Stream");   adodbStream.Type=1;//1=adTypeBinary   adodbStream.Open();
  adodbStream.write(xmlHTTP.responseBody);
  adodbStream.SaveToFile(strLocalURL,2);   adodbStream.Close();
  adodbStream=null;   xmlHTTP=null;    } catch(e) {   window.confirm("下载URL出错!"); } //window.confirm("下载完成."); }


//检验连接是否有效

复制代码 代码如下:

function getXML(URL)  { var xmlhttp = new ActiveXObject("microsoft.xmlhttp"); xmlhttp.Open("GET",URL, false);  try {    xmlhttp.Send();
} catch(e){} finally  {   var result = xmlhttp.responseText;   if(result)    {    if(xmlhttp.Status==200)    {     return(true);
   }    else     {     return(false);
   }   }   else    {
   return(false);   } } }


//POST代替FORM

复制代码 代码如下:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wgddgs.html