js知识3

文档状态改变

<iframe src="a.html" id="f" name="f" 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 NAME="save" CONTENT="history">
<STYLE>
   .sHistory {behavior:url(#default#savehistory);}
</STYLE>
</HEAD>
<BODY>
<INPUT class=sHistory 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

<SCRIPT language="VBScript">
Function URLEncoding(vstrIn)
    strReturn = ""
    For i = 1 To Len(vstrIn)
        ThisChr = Mid(vStrIn,i,1)
        If Abs(Asc(ThisChr)) < &HFF Then
            strReturn = strReturn & ThisChr
        Else
            innerCode = Asc(ThisChr)
            If innerCode < 0 Then
                innerCode = innerCode + &H10000
            End If
            Hight8 = (innerCode  And &HFF00)\ &HFF
            Low8 = innerCode And &HFF
            strReturn = strReturn & "%" & Hex(Hight8) &  "%" & Hex(Low8)
        End If
    Next
    URLEncoding = strReturn
End Function
Function bytes2BSTR(vIn)
    strReturn = ""
    For i = 1 To LenB(vIn)
        ThisCharCode = AscB(MidB(vIn,i,1))
        If ThisCharCode < &H80 Then
            strReturn = strReturn & Chr(ThisCharCode)
        Else
            NextCharCode = AscB(MidB(vIn,i+1,1))
            strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode))
            i = i + 1
        End If
    Next
    bytes2BSTR = strReturn
End Function
dim strA,oReq
strA = URLEncoding("submit1=Submit&text1=中文")
set oReq = CreateObject("MSXML2.XMLHTTP")
oReq.open "POST","http://ServerName/VDir/TstResult.asp",false
oReq.setRequestHeader "Content-Length",Len(strA)
oReq.setRequestHeader "CONTENT-TYPE","application/x-www-form-urlencoded"
oReq.send strA
msgbox bytes2BSTR(oReq.responseBody)
</SCRIPT>
//readyState是xmlhttp返回数据的进度,0=载入中,1=未初始化,2=已载入,3=运行中,4=完成

组件是否安装

isComponentInstalled("{6B053A4B-A7EC-4D3D-4567-B8FF8A1A5739}", "componentID"))

检查网页是否存在

function CheckURL(URL)
{
  var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  xmlhttp.Open("GET",URL, false);
  try
  {
    xmlhttp.Send();
    var result = xmlhttp.status;
  }
  catch(e) {return(false); }
  if(result==200)
  {
    return true;
  }
  xmlhttp = null;
  return false;
}

连接数据库

你可能感兴趣的:(prototype,F#,Microsoft,asp)