一. 静态属性
下面是静态类里的方法,事实上,我们这里用属性,甚至是常量 更好一些.
var InParamsClass =
{
//IE临时目录。
TempPath : function GetTempPath()
{
try
{
var WshShell = new ActiveXObject("WScript.Shell");
var keyValue = WshShell.RegRead("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Cache\\Paths\\Directory");
var iPos = keyValue.indexOf('Content.IE');
return keyValue.substring(0,iPos);
}
catch(e)
{
return "c:\\";
}
} ,
TempFile : ""
}
{
//IE临时目录。
TempPath : function GetTempPath()
{
try
{
var WshShell = new ActiveXObject("WScript.Shell");
var keyValue = WshShell.RegRead("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Cache\\Paths\\Directory");
var iPos = keyValue.indexOf('Content.IE');
return keyValue.substring(0,iPos);
}
catch(e)
{
return "c:\\";
}
} ,
TempFile : ""
}
在属性 TempPath 里,不能包含复杂的逻辑和返回值. 下面是用属性的表示方法:
var InParamsClass =
{
//IE临时目录。
TempPath : "" ,
TempFile : ""
}
InParamsClass.TempPath = GetTempPath() ;
function GetTempPath()
{
try
{
var WshShell = new ActiveXObject("WScript.Shell");
var keyValue = WshShell.RegRead("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Cache\\Paths\\Directory");
var iPos = keyValue.indexOf('Content.IE');
return keyValue.substring(0,iPos);
}
catch(e)
{
return "c:\\";
}
}
{
//IE临时目录。
TempPath : "" ,
TempFile : ""
}
InParamsClass.TempPath = GetTempPath() ;
function GetTempPath()
{
try
{
var WshShell = new ActiveXObject("WScript.Shell");
var keyValue = WshShell.RegRead("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Cache\\Paths\\Directory");
var iPos = keyValue.indexOf('Content.IE');
return keyValue.substring(0,iPos);
}
catch(e)
{
return "c:\\";
}
}
调用 InParamsClass.OpenFile
二.利用钩子,查看打开模态窗口的地址
// 在 IE 状态栏显示要打开的路径. yxh .
window.showModalDialog2=window.showModalDialog ;
window.showModalDialog = function(a,b,c)
{
window.status = "路径:" + a + "参数:" + c;
Log( "路径:" + a + "参数:" + c ) ;
c = GetString(c) ;
c = trimStr(c) ;
c = RemoveValue( c,"status") ;
c = RemoveValue(c,"resizeble") ;
c = RemoveValue(c,"scroll") ;
b =GetString(b) ;
var retVal = window.showModalDialog2(a , b ,GetString(c) ) ;
return retVal ;
}
function RemoveValue(InParams ,str)
{
var retVal = InParams ;
var num = InParams.indexOf(str) ;
if ( num >= 0)
{
if ( num == InParams.indexOf(str + ":0" ) )
{
retVal = InParams.substring(0,num) + InParams.substring( num + str.length + 2 , InParams.length) ;
}
else if ( num == InParams.indexOf(str + ":no") )
{
retVal = InParams.substring(0,num) + InParams.substring( num +str.length + 3 , InParams.length) ;
}
retVal = retVal.replace(";;",";") ;
}
return retVal ;
}
function trimStr(str)
{
var re = /\s*(\S[^\0]*\S)\s*/;
re.exec(str);
return RegExp.$1;
}
function GetString(str)
{
if ( str == null || str == undefined ) return "" ;
else return str ;
}
function Log(str)
{
var fso = new ActiveXObject("Scripting.FileSystemObject");
var log = fso.OpenTextFile("C:\\Inetpub\\wwwroot\\log.txt", 8 );
var dt = new Date() ;
log.WriteLine( dt.toLocaleTimeString() + " " + str );
log.Close();
}
window.showModalDialog2=window.showModalDialog ;
window.showModalDialog = function(a,b,c)
{
window.status = "路径:" + a + "参数:" + c;
Log( "路径:" + a + "参数:" + c ) ;
c = GetString(c) ;
c = trimStr(c) ;
c = RemoveValue( c,"status") ;
c = RemoveValue(c,"resizeble") ;
c = RemoveValue(c,"scroll") ;
b =GetString(b) ;
var retVal = window.showModalDialog2(a , b ,GetString(c) ) ;
return retVal ;
}
function RemoveValue(InParams ,str)
{
var retVal = InParams ;
var num = InParams.indexOf(str) ;
if ( num >= 0)
{
if ( num == InParams.indexOf(str + ":0" ) )
{
retVal = InParams.substring(0,num) + InParams.substring( num + str.length + 2 , InParams.length) ;
}
else if ( num == InParams.indexOf(str + ":no") )
{
retVal = InParams.substring(0,num) + InParams.substring( num +str.length + 3 , InParams.length) ;
}
retVal = retVal.replace(";;",";") ;
}
return retVal ;
}
function trimStr(str)
{
var re = /\s*(\S[^\0]*\S)\s*/;
re.exec(str);
return RegExp.$1;
}
function GetString(str)
{
if ( str == null || str == undefined ) return "" ;
else return str ;
}
function Log(str)
{
var fso = new ActiveXObject("Scripting.FileSystemObject");
var log = fso.OpenTextFile("C:\\Inetpub\\wwwroot\\log.txt", 8 );
var dt = new Date() ;
log.WriteLine( dt.toLocaleTimeString() + " " + str );
log.Close();
}
调用: window.showModalDialog("a.htm") ;
三. 类型转换:
定义一个Array可以这样:
var m_GridMenu = new Array (
{"text" :"打开信息" , "img": "../images/open.gif" , "action" :"post" , "subMenuControlID":"gridMenu1"} ,
{"text" :"-" , "img": "../images/open.gif" , "action" :"post"} ,
{"text" :"标记为已读" , "img": "../images/readMail.gif" , "action" :"markRead"} ,
{"text" :"标记为未读" , "img": "../images/unreadMail.gif" , "action" :"markUnread"}
{"text" :"打开信息" , "img": "../images/open.gif" , "action" :"post" , "subMenuControlID":"gridMenu1"} ,
{"text" :"-" , "img": "../images/open.gif" , "action" :"post"} ,
{"text" :"标记为已读" , "img": "../images/readMail.gif" , "action" :"markRead"} ,
{"text" :"标记为未读" , "img": "../images/unreadMail.gif" , "action" :"markUnread"}
如果把 Array 构造函数里面的内容,定义在别的地方, 但是,我的程序要提供另一个方式,就是在程序一个地方存储这个 Array 对象的内容(element.innerHTML ),在脚本的其它地方操作它. 这里用到了一个小技巧:
var arrayItems ;
eval( "arrayItems = new Array( " + element.innerHTML + ") ;" ) ;
eval( "arrayItems = new Array( " + element.innerHTML + ") ;" ) ;