JAvascriptテクニック使用コレクション
60500 ワード
function getnetprinter()
{
var obj=new ActiveXObject("WScript.Network");
var netprinter=obj.EnumPrinterConnections();
for(i=0;i<netprinter.Count();i+=2)
{
document.writeln(netprinter.Item(i)+"="+netprinter.Item(i+1));
}
}
:getdiskinfo('c')
function getdiskinfo(para)
{
var fs=new ActiveXObject("scripting.filesystemobject");
d=fs.GetDrive(para);
s=" :" + d.VolumnName;
s+="------" + " :" + d.FreeSpace/1024/1024 + "M";
s+="------" + " :" + d.serialnumber;
alert(s)
}
function getprocessnum()
{
var pnsys=new ActiveXObject("WScript.shell");
pn=pnsys.Environment("PROCESS");
alert(pn("WINDIR"));
}
function runcalc()
{
var calc=new ActiveXObject("WScript.shell");
calc.Run("calc");
}
function readreg()
{
var myreadreg=new ActiveXObject("WScript.shell");
try{
alert(myreadreg.RegRead("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\\NeroCheck"));
}
catch(e)
{
alert(" !");
}
}
function writereg()
{
var mywritereg=new ActiveXObject("WScript.shell");
try{
mywritereg.RegWrite("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\\MyTest","c:\\mytest.exe");
alert(" !");
}
catch(e)
{
alert(" !");
}
}
function delreg()
{
var mydelreg=new ActiveXObject("WScript.shell");
if(confirm(" ?"))
{
try{
mydelreg.RegDelete("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\\MyTest");
alert(" !");
}
catch(e)
{
alert(" ");
}
}
}
function netinfo()
{
var mynetinfo=new ActiveXObject("WScript.network");
alert(" :"+mynetinfo.ComputerName+" :"+mynetinfo.UserDomain+" :"+mynetinfo.UserName);
}
(Fonts,AllUsersDesktop,Desktop,MyDocuments,Recent.....)
function getspecialfolder()
{
var mygetfolder=new ActiveXObject("WScript.shell");
if(mygetfolder.SpecialFolders("Fonts")!=null)
{
alert(mygetfolder.SpecialFolders("Fonts"));
}
}
:getfileinfo('E:\\MyPlace\\TEST\\myjs.htm')
function getfileinfo(para)
{
var myfile=new ActiveXObject("scripting.filesystemobject");
var fi=myfile.GetFile(para);
alert(" :"+fi.type+" :"+fi.size/1024/1024+"M"+" :"+fi.DateLastAccessed);
}
function clientInfo()
{
strClientInfo="availHeight= "+window.screen.availHeight+"
"+
"availWidth= "+window.screen.availWidth+"
"+
"bufferDepth= "+window.screen.bufferDepth+"
"+
"colorDepth= "+window.screen.colorDepth+"
"+
"colorEnable= "+window.navigator.cookieEnabled+"
"+
"cpuClass= "+window.navigator.cpuClass+"
"+
"height= "+window.screen.height+"
"+
"javaEnable= "+window.navigator.javaEnabled()+"
"+
"platform= "+window.navigator.platform+"
"+
"systemLanguage= "+window.navigator.systemLanguage+"
"+
"userLanguage= "+window.navigator.userLanguage+"
"+
"width= "+window.screen.width;
alert(strClientInfo);
}
Dilog Helper
function changeColor()//Dilog Helper
{
var sColor=dlgHelper.choosecolordlg();
sColor=sColor.toString(16);
if (sColor.length < 6) {
var sTempString = "000000".substring(0,6-sColor.length);
sColor = sTempString.concat(sColor);
}
alert(sColor);
mybody.style.backgroundColor=sColor;
}
function getFonts()//Dilog Helper
{
var strFonts="";
for(var i=1;i<dlgHelper.fonts.count;i++)
{
strFonts=strFonts+dlgHelper.fonts(i)+"|";
}
alert(strFonts);
}
function getBlockFormat()//Dilog Helper ( : 1、 2....)
{
var strBlockFormat="";
for(var i=1;i<dlgHelper.BlockFormats.count;i++)
{
strBlockFormat=strBlockFormat+dlgHelper.BlockFormats(i)+"|";
}
alert(strBlockFormat);
}
function createTxtLink()
{
var sText=document.selection.createRange();
if(sText.text!="")
{
document.execCommand("CreateLink");
if(sText.parentElement().tagName=="A")
{
sText.parentElement().innerText=sText.parentElement().href;
document.execCommand("ForeColor",false,"#ffff00");
}
}
}
BlockFormats, Select(id myselect) BlockFormat
// fillselect() changeformat()
// execCommand :Executes a command over the given selection or text range
function fillselect()
{
var item=document.createElement("OPTION")
item.text=" ";
item.value="";
myselect.add(item);
for(var i=1;i<dlgHelper.BlockFormats.count;i++)
{
item=document.createElement("OPTION");
item.text=dlgHelper.BlockFormats(i);
item.value=dlgHelper.BlockFormats(i);
myselect.add(item);
}
}
function changeformat()
{
var sSelect=myselect.options[myselect.selectedIndex].value;
document.execCommand("FormatBlock",false,sSelect);
}
, :ShowDriveType('c:')
function ShowDriveType(drvpath)
{
fs=new ActiveXObject("scripting.filesystemobject");
disk=fs.GetDrive(drvpath);
var whichtype="";
switch(disk.DriveType)
{
case 0:
whichtype="Unknown"
break
case 1:
whichtype="Removable"
break
case 2:
whichtype="Fixed"
break
case 3:
whichtype="Network"
break
case 4:
whichtype="CD-ROM"
break
case 5:
whichtype="RAM Disk"
}
alert(whichtype);
SerialNumber
try{
alert(disk.SerialNumber);
}
catch(e){
alert(e.message);
}
alert(disk.VolumeName);//
}
</script>
-------------------------
<OBJECT id=dlgHelper CLASSID="clsid:3050f819-98b5-11cf-bb82-00aa00bdce0b" width="0px" height="0px"></OBJECT>
var mywritereg=new ActiveXObject("WScript.shell");
try{
mywritereg.RegWrite("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\\MyTest","c:\\mytest.exe");
alert(" !");
}
catch(e)
{
alert(" !");
}
}
•
event.srcElement.tagName
event.srcElement.type
•
event.srcElement.setCapture();
event.srcElement.releaseCapture();
•
event.keyCode
event.shiftKey
event.altKey
event.ctrlKey
•
event.returnValue
•
event.x
event.y
•
document.activeElement
•
document.captureEvents(Event.KEYDOWN);
•
document.all("txt").focus();
document.all("txt").select();
•
document.execCommand
• COOKIE
document.cookie
•
document.oncontextmenu
•
document.createElement("SPAN");
• :
document.elementFromPoint(event.x,event.y).tagName=="TD
document.elementFromPoint(event.x,event.y).appendChild(ms)
•
document.images[ ]
•
document.onmousedown=scrollwindow;
•
document. .elements[ ]
•
document.all.xxx.detachEvent('onclick',a);
•
navigator.plugins
•
typeof($js_libpath) == "undefined"
•
.options[ ]
.options.length
•
document.getElementsByName("r1");
document.getElementById(id);
•
timer=setInterval('scrollwindow()',delay);
clearInterval(timer);
•UNCODE
escape() ,unescape
•
obj.parentElement(dhtml)
obj.parentNode(dom)
•
TableID.moveRow(2,1)
• CSS
document.all.csss.href = "a.css";
•
display:inline
•
hidefocus=true
•
style="word-break:break-all"
•
<meta HTTP-EQUIV="refresh" CONTENT="8;URL=http://c98.yeah.net">
•
<a href="mailto:[email protected]?subject=ccc&body=xxxyyy">
•
obj.scrollIntoView(true)
•
<a name="first">
<a href="#first">anchors</a>
•
location.search();
•
obj.contenteditable=true
•
obj.execCommand
•
/[^\x00-\xff]/
/[\u4e00-\u9fa5]/
•
word-wrap: break-word; word-break: break-all;
•
<IFRAME src="1.htm" width=300 height=180 allowtransparency></iframe>
• style
obj.style.cssText
•HTML
document.documentElement.innerHTML
• style
document.styleSheets[0]
•style
document.styleSheets[0].rules[0]
• , 。
<a href="javascript:function()">word</a>
•
asp:
request.servervariables("HTTP_REFERER")
javascript:
document.referrer
•
CollectGarbage();
•
document.oncontextmenu = function() { return false;}
•
<noscript><iframe src="*.htm"></iframe></noscript>
• <body oncontextmenu="return false" ondragstart="return false" onselectstart ="return false" onselect="document.selection.empty()" oncopy="document.selection.empty()" onbeforecopy="return false"onmouseup="document.selection.empty()>
•
<input type=text onpaste="return false">
•
<link rel="Shortcut Icon" href="favicon.ico">
favicon.ico 16*16 16 ,
•
<link rel="Bookmark" href="favicon.ico">
•
<input type=button value= onclick="window.location = 'view-source:'+ 'http://www.csdn.net/'">
•
<input style="ime-mode:disabled">
•
<input type=text name=text1 value="123" onfocus="this.select()">
•ENTER
<input onkeydown="if(event.keyCode==13)event.keyCode=9">
•
<input type=text value="123" onfocus="alert(this.defaultValue)">
•title
obj.title = "123 sdfs "
•
var n1 = new Date("2004-10-10".replace(/-/g, "\/")).getTime()
•
win.closed
•checkbox
<input type=checkbox style="position: absolute; clip:rect(5px 15px 15px 5px)"><br>
•
document.selection.createRange().duplicate().text
•
<input type=text autocomplete=on>
<input type=text autocomplete=off>
•
<body onload="window.resizeTo(window.screen.width - 4,window.screen.height-50);window.moveTo(-4,-4)">
• IE
window.open("aa.htm", "meizz", "fullscreen=7");
• /
alert(decodeURIComponent(encodeURIComponent("http:// .com?as= hehe")))
encodeURIComponent ":"、"/"、";" "?"
•
<tr onmouseover="this.bgColor='#f0f0f0'" onmouseout="this.bgColor='#ffffff'">
//サイズ別
s += "\r
:"+ document.body.clientWidth;
s += "\r
:"+ document.body.clientHeight;
s += "\r
:"+ document.body.offsetWeight +" ( )";
s += "\r
:"+ document.body.offsetHeight +" ( )";
s += "\r
:"+ document.body.scrollWidth;
s += "\r
:"+ document.body.scrollHeight;
s += "\r
:"+ document.body.scrollTop;
s += "\r
:"+ document.body.scrollLeft;
s += "\r
:"+ window.screenTop;
s += "\r
:"+ window.screenLeft;
s += "\r
:"+ window.screen.height;
s += "\r
:"+ window.screen.width;
s += "\r
:"+ window.screen.availHeight;
s += "\r
:"+ window.screen.availWidth;
//正則マッチング
: [\u4e00-\u9fa5]
( ):[^\x00-\xff]
:
[\s| ]*\r
HTML :/<(.*)>.*<\/\1>|<(.*) \/>/
:(^\s*)|(\s*$)( vbscript trim )
Email :\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
URL :http://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?
:
:
:onkeyup="value=value.replace(/[^\u4E00-\u9FA5]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\u4E00-\u9FA5]/g,''))"
1. : onkeyup="value=value.replace(/[^\uFF00-\uFFFF]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\uFF00-\uFFFF]/g,''))"
2. :onkeyup="value=value.replace(/[^\d]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"
3. :onkeyup="value=value.replace(/[\W]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"
//画像削除ツールバー
<IMG SRC="mypicture.jpg" HEIGHT="100px" WIDTH="100px" GALLERYIMG="false">
or
<head>
<meta http-equiv="imagetoolbar" content="no">
</head>
//ヒントなしで閉じる
function Close()
{
var ua=navigator.userAgent
var ie=navigator.appName=="Microsoft Internet Explorer"?true:false
if(ie)
{
var IEversion=parseFloat(ua.substring(ua.indexOf("MSIE ")+5,ua.indexOf(";",ua.indexOf("MSIE "))))
if(IEversion< 5.5)
{
var str = '<object id=noTipClose classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11">'
str += '<param name="Command" value="Close"></object>';
document.body.insertAdjacentHTML("beforeEnd", str);
document.all.noTipClose.Click();
}
else
{
window.opener =null;
window.close();
}
}
else
{
window.close()
}
}
//コントロールの絶対位置を取得(1)
<script language="javascript">
function getoffset(e)
{
var t=e.offsetTop;
var l=e.offsetLeft;
while(e=e.offsetParent)
{
t+=e.offsetTop;
l+=e.offsetLeft;
}
var rec = new Array(1);
rec[0] = t;
rec[1] = l;
return rec
}
</script>
//コントロールの絶対位置を取得する(2)
oRect = obj.getBoundingClientRect();
oRect.left
oRect.
//テキストの最後にカーソルを合わせる
<script language="javascript">
function cc()
{
var e = event.srcElement;
var r =e.createTextRange();
r.moveStart('character',e.value.length);
r.collapse(true);
r.select();
}
</script>
<input type=text name=text1 value="123" onfocus="cc()">
//ページの読み込みと終了の特効
<meta http-equiv="Page-Enter" content="revealTrans(duration=x, transition=y)">
<meta http-equiv="Page-Exit" content="revealTrans(duration=x, transition=y)">
。duration , 。transition
, 1-23:
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//印刷の設定
<object id="factory" style="display:none" viewastext
classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814"
codebase="http://www.meadroid.com/scriptx/ScriptX.cab#Version=5,60,0,360"
></object>
<input type=button value= onclick="factory.printing.PageSetup()">
<input type=button value= onclick="factory.printing.Preview()">
<script language=javascript>
function window.onload()
{
// -- advanced features
factory.printing.SetMarginMeasure(2) // measure margins in inches
factory.printing.SetPageRange(false, 1, 3) // need pages from 1 to 3
factory.printing.printer = "HP DeskJet 870C"
factory.printing.copies = 2
factory.printing.collate = true
factory.printing.paperSize = "A4"
factory.printing.paperSource = "Manual feed"
// -- basic features
factory.printing.header = " &b &b , &p / &P "
factory.printing.footer = "( )"
factory.printing.portrait = false
factory.printing.leftMargin = 0.75
factory.printing.topMargin = 1.5
factory.printing.rightMargin = 0.75
factory.printing.bottomMargin = 1.5
}
function Print(frame) {
factory.printing.Print(true, frame) // print with prompt
}
</script>
<input type=button value=" " onclick="factory.printing.Print(false)">
<input type=button value=" " onclick="factory.printing.PageSetup()">
<input type=button value=" " onclick="factory.printing.Preview()"><br>
<a href="http://www.meadroid.com/scriptx/docs/printdoc.htm?static" target=_blank> , , </a>
//印刷プレビュー
WebBrowser.ExecWB(1,1)
Web.ExecWB(2,1) IE ,
Web.ExecWB(4,1)
Web.ExecWB(6,1)
Web.ExecWB(7,1)
Web.ExecWB(8,1)
Web.ExecWB(10,1)
Web.ExecWB(15,1) ,
Web.ExecWB(17,1)
Web.ExecWB(22,1)
Web.ExecWB(45,1)
<style media=print>
.Noprint{display:none;}<!-- -->
.PageNext{page-break-after: always;}<!-- -->
</style>
<object id="WebBrowser" width=0 height=0 classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2">
</object>
<center class="Noprint" >
<input type=button value= onclick=document.all.WebBrowser.ExecWB(6,1)>
<input type=button value= onclick=document.all.WebBrowser.ExecWB(6,6)>
<input type=button value= onclick=document.all.WebBrowser.ExecWB(8,1)>
</p>
<p> <input type=button value= onclick=document.all.WebBrowser.ExecWB(7,1)>
</center> //
<script language="JavaScript">
var HKEY_Root,HKEY_Path,HKEY_Key;
HKEY_Root="HKEY_CURRENT_USER";
HKEY_Path="\\Software\\Microsoft\\Internet Explorer\\PageSetup\\";
//ページ印刷のヘッダーフッターを空にする
function PageSetup_Null()
{
try
{
var Wsh=new ActiveXObject("WScript.Shell");
HKEY_Key="header";
Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"");
HKEY_Key="footer";
Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"");
}
catch(e){}
}
//ページ印刷のヘッダーフッターをデフォルトに設定
function PageSetup_Default()
{
try
{
var Wsh=new ActiveXObject("WScript.Shell");
HKEY_Key="header";
Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"&w&b ,&p/&P");
HKEY_Key="footer";
Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"&u&b&d");
}
catch(e){}
}
</script>
<input type="button" value=" " onclick=PageSetup_Null()>
<input type="button" value=" " onclick=PageSetup_Default()> //
function checkBrowser()
{
this.ver=navigator.appVersion
this.dom=document.getElementById?1:0
this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom)?1:0;
this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0;
this.ie4=(document.all && !this.dom)?1:0;
this.ns5=(this.dom && parseInt(this.ver) >= 5) ?1:0;
this.ns4=(document.layers && !this.dom)?1:0;
this.mac=(this.ver.indexOf('Mac') > -1) ?1:0;
this.ope=(navigator.userAgent.indexOf('Opera')>-1);
this.ie=(this.ie6 || this.ie5 || this.ie4)
this.ns=(this.ns4 || this.ns5)
this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns5 || this.ns4 || this.mac || this.ope)
this.nbw=(!this.bw)
return this;
}
//コンテンツの幅と高さの計算
<SCRIPT language="javascript">
function test(obj)
{
var range = obj.createTextRange();
alert(" : " + range.boundingWidth
+ "px\r
: " + range.boundingHeight + "px");
}
</SCRIPT>
<BODY>
<Textarea id="txt" height="150">sdf</textarea><INPUT type="button" value=" " onClick="test(txt)">
</BODY>
//モードなしのプロンプトボックス
function modelessAlert(Msg)
{
window.showModelessDialog("javascript:alert(\""+escape(Msg)+"\");window.close();","","status:no;resizable:no;help:no;dialogHeight:height:30px;dialogHeight:40px;");
}
//シールドキー
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<noscript><meta http-equiv="refresh" content="0;url=about:noscript"></noscript>
<title> 、Ctrl+N、Shift+F10、Alt+F4、F11、F5 、 </title>
</head>
<body>
<script language="Javascript"><!--
// 、Ctrl+N、Shift+F10、F11、F5 、
//Author: meizz( ) 2002-6-18
function document.oncontextmenu(){event.returnValue=false;}//
function window.onhelp(){return false} // F1
function document.onkeydown()
{
if ((window.event.altKey)&&
((window.event.keyCode==37)|| // Alt+ ←
(window.event.keyCode==39))) // Alt+ →
{
alert(" ALT+ !");
event.returnValue=false;
}
/* : Alt+ ,
Alt+ , Alt ,
, 。
Alt , 。*/
if ((event.keyCode==8) || //
(event.keyCode==116)|| // F5
(event.ctrlKey && event.keyCode==82)){ //Ctrl + R
event.keyCode=0;
event.returnValue=false;
}
if (event.keyCode==122){event.keyCode=0;event.returnValue=false;} // F11
if (event.ctrlKey && event.keyCode==78) event.returnValue=false; // Ctrl+n
if (event.shiftKey && event.keyCode==121)event.returnValue=false; // shift+F10
if (window.event.srcElement.tagName == "A" && window.event.shiftKey)
window.event.returnValue = false; // shift
if ((window.event.altKey)&&(window.event.keyCode==115)) // Alt+F4
{
window.showModelessDialog("about:blank","","dialogWidth:1px;dialogheight:1px");
return false;
}
}
</script>
、Ctrl+N、Shift+F10、Alt+F4、F11、F5 、
</body>
</html>
//
<style>
@media print{
* {display:none}
}
</style>
//移動するレイヤー、ドラッグ
1.<span style='position:absolute;width:200;height:200;background:red' onmousedown=MouseDown(this) onmousemove=MouseMove() onmouseup=MouseUp()>meizz</span>
<script language=javascript>
var Obj;
function MouseDown(obj)
{
Obj=obj;
Obj.setCapture();
Obj.l=event.x-Obj.style.pixelLeft;
Obj.t=event.y-Obj.style.pixelTop;
}
function MouseMove()
{
if(Obj!=null)
{
Obj.style.left = event.x-Obj.l;
Obj.style.top = event.y-Obj.t;
}
}
function MouseUp()
{
if(Obj!=null)
{
Obj.releaseCapture();
Obj=null;
}
}
</script>
2.
<div id="myDiv" src="logo.gif" ondrag="doDrag();" onmouseover="this.style.cursor='hand'" style="position:absolute;left=100;top=100;" onmousedown="doMouseDown();">
<a href="#" onclick="return false"><h1>wlecome</h1></a>
</div>
<script language="JavaScript" type="text/javascript">
var orgMouseX;
var orgMouseY;
var orgObjX;
var orgObjY;
function doDrag()
{
var myObject=document.all.myDiv;
var x=event.clientX;
var y=event.clientY;
myObject.style.left=x-(orgMouseX-orgObjX);
myObject.style.top=y-(orgMouseY-orgObjY);
}
function doMouseDown()
{
orgMouseX=event.clientX;
orgMouseY=event.clientY;
orgObjX=parseInt(document.all.myDiv.style.left);
orgObjY=parseInt(document.all.myDiv.style.top);
}
</script>
//文書ステータスの変更
<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>
//更新後も変わらないテキストボックス
//クリップボードへのアクセス
//操作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(" .");
}
//接続が有効かどうかを確認する
//コンポーネントisComponentInstalled("{6 B 053 A 4 B-A 7 EC-4 D 3 D-4567-B 8 FF 8 A 1 A 5739}","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;
}
//データベースの接続
<script language="javascript">
// JavaScript
var conn = new ActiveXObject("ADODB.Connection");
conn.Open("Provider=SQLOLEDB.1; Data Source=localhost; User ID=sa; "
+"Password=; Initial Catalog=pubs");
var rs = new ActiveXObject("ADODB.Recordset");
var sql="select * from authors";
rs.open(sql, conn);
shtml = "<table width='100%' border=1>";
shtml +="<tr bgcolor='#f4f4f4'><td>au_id</td><td>au_lname</td><td>au_fname</td><td>phone</td><td>address</td><td> city</td><td>state</td><td>zip</td></tr>";
while(!rs.EOF)
{
shtml += "<tr><td>" + rs("au_id") + "</td><td>" + rs("au_lname") + "</td><td>" + rs("au_fname") + "</td><td>" + rs("phone") + "</td><td>" + rs("address") + "</td><td>" + rs("city") + "</td><td>" + rs("state") + "</td><td>" + rs("zip") + "</td></tr>";
rs.moveNext;
}
shtml += "</table>";
document.write(shtml);
rs.close();
rs = null;
conn.close();
conn = null;
</script>
//データアイランドの使用
srno:
times:
< input="first"TYPE=buton value="<<第1条記録"onclick="
//取得パラメータ
<body>
<a href="javascript:location.href=location.href + '?a=1&b=2'">search</a>
<script language="JavaScript">
<!--
var a = location.search.substr(1);
if(a.length>0)
{
var re = /([^&]*?)\=([^&]*)/g
var s = a.match(re);
for(var i= 0;i<s.length;i++)
{
alert(s[i]);
alert(s[i].split("=")[1]);
}
}
//-->
</script>
</body>
//編集可能SELECT
<input type=text name=re_name style="width:100px;height:21px;font-size:10pt;">
<span style="width:18px;border:0px solid red;">
<select name="r00" style="margin-left:-100px;width:118px; background-color:#FFEEEE;" onChange="document.all.re_name.value=this.value;">
<option value="1">11111111<option>
<option value="2">222222</option>
<option value="3">333333</option>
</select>
</span>
//カーソル位置の設定
function getCaret(textbox)
{
var control = document.activeElement;
textbox.focus();
var rang = document.selection.createRange();
rang.setEndPoint("StartToStart",textbox.createTextRange())
control.focus();
return rang.text.length;
}
function setCaret(textbox,pos)
{
try
{
var r =textbox.createTextRange();
r.moveStart('character',pos);
r.collapse(true);
r.select();
}
catch(e)
{}
}
function selectLength(textbox,start,len)
{
try
{
var r =textbox.createTextRange();
r.moveEnd('character',len-(textbox.value.length-start));
r.moveStart('character',start);
r.select();
}
catch(e)
{//alert(e.description)}
}
function insertAtCaret(textbox,text)
{
textbox.focus();
document.selection.createRange().text = text;
}
//ページ内検索
function findInPage(str)
{
var txt, i, found,n = 0;
if (str == "")
{
return false;
}
txt = document.body.createTextRange();
for (i = 0; i <= n && (found = txt.findText(str)) != false; i++)
{
txt.moveStart("character", 1);
txt.moveEnd("textedit");
}
if (found)
{
txt.moveStart("character", -1);
txt.findText(str);
txt.select();
txt.scrollIntoView();
n++;
}
else
{
if (n > 0)
{
n = 0;
findInPage(str);
}
else
{
alert(str + "... 。
!");
}
}
return false;
}
//本
http://www.itpub.net/attachment.php?s=&postid=1894598http://www.wrclub.net/down/listdown.aspx?id=1341//操作EXECL
<script language="javascript">
function jStartExcel() {
var xls = new ActiveXObject ( "Excel.Application" );
xls.visible = true;
var newBook = xls.Workbooks.Add;
newBook.Worksheets.Add;
newBook.Worksheets(1).Activate;
xls.ActiveWorkBook.ActiveSheet.PageSetup.Orientation = 2;
xls.ActiveWorkBook.ActiveSheet.PageSetup.PaperSize = 5;
newBook.Worksheets(1).Columns("A").columnwidth=50;
newBook.Worksheets(1).Columns("A").WrapText = true;
newBook.Worksheets(1).Columns("B").columnwidth=50;
newBook.Worksheets(1).Columns("B").WrapText = true;
newBook.Worksheets(1).Range("A1:B1000").NumberFormat = "0";
newBook.Worksheets(1).Range("A1:B1000").HorizontalAlignment = -4131;
newBook.Worksheets(1).Cells(1,1).Interior.ColorIndex="15";
newBook.Worksheets(1).Cells(1,1).value="First Column, First Cell";
newBook.Worksheets(1).Cells(2,1).value="First Column, Second Cell";
newBook.Worksheets(1).Cells(1,2).value="Second Column, First Cell";
newBook.Worksheets(1).Cells(2,2).value="Second Column, Second Cell";
newBook.Worksheets(1).Name="My First WorkSheet";
}
</script>
//カスタムプロンプト
<a href="#" title=" ">tip</a>
<script Language="JavaScript">
//*********** .*********************
tPopWait=50;// tWait 。
tPopShow=5000;// tShow
showPopStep=20;
popOpacity=99;
//*************** *****************
sPop=null;
curShow=null;
tFadeOut=null;
tFadeIn=null;
tFadeWaiting=null;
document.write("<style type='text/css'id='defaultPopStyle'>");
document.write(".cPopText { background-color: #F8F8F5;color:#000000; border: 1px #000000 solid;font-color: font-size: 12px; padding-right: 4px; padding-left: 4px; height: 20px; padding-top: 2px; padding-bottom: 2px; filter: Alpha(Opacity=0)}");
document.write("</style>");
document.write("<div id='dypopLayer' style='position:absolute;z-index:1000;' class='cPopText'></div>");
function showPopupText(){
var o=event.srcElement;
MouseX=event.x;
MouseY=event.y;
if(o.alt!=null && o.alt!=""){o.dypop=o.alt;o.alt=""};
if(o.title!=null && o.title!=""){o.dypop=o.title;o.title=""};
if(o.dypop!=sPop) {
sPop=o.dypop;
clearTimeout(curShow);
clearTimeout(tFadeOut);
clearTimeout(tFadeIn);
clearTimeout(tFadeWaiting);
if(sPop==null || sPop=="") {
dypopLayer.innerHTML="";
dypopLayer.style.filter="Alpha()";
dypopLayer.filters.Alpha.opacity=0;
}
else {
if(o.dyclass!=null) popStyle=o.dyclass
else popStyle="cPopText";
curShow=setTimeout("showIt()",tPopWait);
}
}
}
function showIt(){
dypopLayer.className=popStyle;
dypopLayer.innerHTML=sPop;
popWidth=dypopLayer.clientWidth;
popHeight=dypopLayer.clientHeight;
if(MouseX+12+popWidth>document.body.clientWidth) popLeftAdjust=-popWidth-24
else popLeftAdjust=0;
if(MouseY+12+popHeight>document.body.clientHeight) popTopAdjust=-popHeight-24
else popTopAdjust=0;
dypopLayer.style.left=MouseX+12+document.body.scrollLeft+popLeftAdjust;
dypopLayer.style.top=MouseY+12+document.body.scrollTop+popTopAdjust;
dypopLayer.style.filter="Alpha(Opacity=0)";
fadeOut();
}
function fadeOut(){
if(dypopLayer.filters.Alpha.opacity<popOpacity) {
dypopLayer.filters.Alpha.opacity+=showPopStep;
tFadeOut=setTimeout("fadeOut()",1);
}
else {
dypopLayer.filters.Alpha.opacity=popOpacity;
tFadeWaiting=setTimeout("fadeIn()",tPopShow);
}
}
function fadeIn(){
if(dypopLayer.filters.Alpha.opacity>0) {
dypopLayer.filters.Alpha.opacity-=1;
tFadeIn=setTimeout("fadeIn()",1);
}
}
document.onmouseover=showPopupText;
</script>
//テキストの挿入
document.onclick =function(){
var oSource = window.event.srcElement;
if(oSource.tagName!="DIV")
return false;
var sel = document.selection;
if (sel!=null) {
var rng = sel.createRange();
if (rng!=null)
rng.pasteHTML("<font color=red> </font>");
}
}
//Netscapteでxmlを操作する
//判断キー値
//FSO禁止
1.コンポーネントregsvr 32/u scrrun.dll 2.PROGIDの変更 HKEY_CLASSES_ROOTScripting.FileSystemObject Scripting.FileSystemObject 3.objectを使用するユーザーに対してHKEY_を変更するCLASSES_ROOTScripting//省略記号
//メディアプレイバージョンの検出
//イメージを比例する
//細線SELECT
function getComputerName()
{
var objWMIService = GetObject("Winmgmts:root\cimv2");
for(e = new Enumerator(objWMIService) ; !e.atEnd() ; e.moveNext())
{
var getComputer = e.item();
return getComputer.Name;
}
}
//じょうけんコンパイル
<script language=javascript>
/*@cc_on @*/
/*@if (@_win32 && @_jscript_version>5)
function window.confirm(str)
{
execScript("n = msgbox('"+ str +"', 257)", "vbscript");
return(n == 1);
}
@end @*/
</script>
//innerText取得
<SCRIPT LANGUAGE="JavaScript">
<!--
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.4.0");
var currNode;
xmlDoc.async = false;
xmlDoc.async = false;
xmlDoc.loadXML("<TABLENAME> </TABLENAME>");
currNode = xmlDoc.documentElement;
var s = currNode.xml;
var r = /\<([^\>\s]*?)[^\>]*?\>([^\<]*?)\<\/\1\>/
var b = s.replace(r,"$2");
alert(b);
//-->
</SCRIPT>
//mergeAttributesは、すべての読み取り/書き込みラベル属性を指定した要素にコピーします.
<SCRIPT>
function fnMerge(){
oSource.children[1].mergeAttributes(oSource.children[0]);
}
</SCRIPT>
<SPAN ID=oSource>
<DIV
ID="oDiv"
ATTRIBUTE1="true"
ATTRIBUTE2="true"
onclick="alert('click');"
onmouseover="this.style.color='#0000FF';"
onmouseout="this.style.color='#000000';"
>
This is a sample <B>DIV</B> element.
</DIV>
<DIV ID="oDiv2">
This is another sample <B>DIV</B> element.
</DIV>
</SPAN>
<INPUT
TYPE="button"
VALUE="Merge Attributes"
onclick="fnMerge()"
>
原文住所:http://www.cnblogs.com/wucf2004/archive/2007/09/29/910799.html
<span style="border:1px solid #000000; position:absolute; overflow:hidden;" >
<select style="margin:-2px;">
<option>1111</option>
<option>11111111111111</option>
<option>111111111</option>
</select></span>
//Import
function Import() {
for( var i=0; i<arguments.length; i++ ) {
var file = arguments[i];
if ( file.match(/\.js$/i))
document.write('<script type=\"text/javascript\" src=\"' + file + '\"></sc' + 'ript>');
else
document.write('<style type=\"text/css\">@import \"' + file + '\" ;</style>');
}
};
//js列挙
<script language="JavaScript">
<!--
//
var flag=false;
function DrawImage(ImgD){
var image=new Image();
var iwidth = 80; //
var iheight = 80; //
image.src=ImgD.src;
if(image.width>0 && image.height>0){
flag=true;
if(image.width/image.height>= iwidth/iheight){
if(image.width>iwidth){
ImgD.width=iwidth;
ImgD.height=(image.height*iwidth)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
else{
if(image.height>iheight){
ImgD.height=iheight;
ImgD.width=(image.width*iheight)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
}
}
//-->
</script>
<img src=".." onload = "DrawImage(this)">
<IE:clientCaps ID="oClientCaps" style="{behavior:url(#default#clientcaps)}" />
<SCRIPT>
var flash="";
WMPVersion= oClientCaps.getComponentVersion("{22D6F312-B0F6-11D0-94AB-0080C74C7E95}","ComponentID");
if (WMPVersion != "") {
flash = "";
var version = WMPVersion.split(",");
var i;
for (i = 0; i < version.length; i++) {
if (i != 0)
flash += ".";
flash += version[i];
}
document.write(" Windows Media Player :"+flash+"<p>");
}
</SCRIPT>
<DIV STYLE="width: 120px; height: 50px; border: 1px solid blue;
overflow: hidden; text-overflow:ellipsis">
<NOBR> , , .</NOBR>
</DIV>
<html>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<head>
<script language="javascript">
var ie =navigator.appName=="Microsoft Internet Explorer"?true:false;
function keyDown(e)
{
if(!ie)
{
var nkey=e.which;
var iekey=' ns ';
var realkey=String.fromCharCode(e.which);
}
if(ie)
{
var iekey=event.keyCode;
var nkey=' ie ';
var realkey=String.fromCharCode(event.keyCode);
if(event.keyCode==32){realkey='\' \''}
if(event.keyCode==13){realkey='\' \''}
if(event.keyCode==27){realkey='\' Esc\''}
if(event.keyCode==16){realkey='\' Shift\''}
if(event.keyCode==17){realkey='\' Ctrl\''}
if(event.keyCode==18){realkey='\' Alt\''}
}
alert('ns :'+nkey+'
'+'ie :'+iekey+'
'+' '+realkey);
}
document.onkeydown = keyDown;
</script>
</head>
<body>
//Javascript Document.
<hr>
<center>
<h3> 。。。。</h3>
</center>
</body>
</html>
doc = new ActiveXObject("Msxml2.DOMDocument");
doc = new ActiveXObject("Microsoft.XMLDOM")
->>
doc = (new DOMParser()).parseFromString(sXML,'text/xml')
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);
}
}
}
//FORMの代わりにPOST
<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=完了
(1)
event.dataTransfer.setData("URL", oImage.src);
sImageURL = event.dataTransfer.getData("URL")
(2)
window.clipboardData.setData("Text",oSource.innerText);
window.clipboardData.getData("Text");
<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>
<p style="page-break-after:always">page1</p>
<p style="page-break-after:always">page2</p>
<meta name="ROBOTS" content=" ">
:
"all": , ;
"none": , ;
"index": ;
"follow": ;
"noindex": , ;
"nofollow":
<object id=min classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11">
<param name="Command" value="Minimize"></object>
<object id=max classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11">
<param name="Command" value="Maximize"></object>
<OBJECT id=close classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11">
<PARAM NAME="Command" value="Close"></OBJECT>
<input type=button value= onclick=min.Click()>
<input type=button value= onclick=max.Click()>
<input type=button value= onclick=close.Click()>
<META HTTP-EQUIV="pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
<META HTTP-EQUIV="expires" CONTENT="0">
<input type=button value= onclick="window.external.ImportExportFavorites(true,'http://localhost');">
<input type=button value= onclick="window.external.ImportExportFavorites(false,'http://localhost');">
<input type=button value= onclick="window.external.ShowBrowserUI('OrganizeFavorites', null)">
<input type=button value= onclick="window.external.ShowBrowserUI('LanguageDialog', null)">
<input type=button value= onclick="window.external.AddFavorite('http://www.google.com/', 'google')">
<input type=button value= onclick="window.external.addChannel('http://www.google.com/')">
<input type=button value= onclick="window.external.showBrowserUI('PrivacySettings',null)">
<input type=text onkeypress="return event.keyCode>=48&&event.keyCode<=57||(this.value.indexOf('.')<0?event.keyCode==46:false)" onpaste="return !clipboardData.getData('text').match(/\D/)" ondragenter="return false">
本文はCSDNブログから来て、転載して出典を明記してください:http://blog.csdn.net/lff642/archive/2008/07/17/2667247.aspx