asp jscript, vbscript 的 动态交互 与 动态加载 By shawl.qiu
说明:
本文想实现的是通过字串或文件形式动态加载另一语言, 并达到交互.
其实鄙人以前有想过这么弄来着, 不过碍于技术问题无法实现.
现在实现对我来说没多大作用, 但最终证实了 两种语言确实能
达到动态加载与动态交互...
那么, 首先我们要了解一些基本的原理, ASP 页的执行序列.
执行顺序按优先级为
1. <script runat="server" language="vbscript">
2. <script runat="server" language="jscript">
3. <% code %>
好了, 你看到 runat 无论那种语言, 执行顺序都排在 <%%> 的前面,
这是我们实现 动态加载 与 动态交互的关键
废话少说, 直接看示例.
目录:
1. jscript 动态加载与动态交互 vbscript
1.1 vbscript.asp
1.2 ByFile.asp
1.3 ByString.asp
2. vbscript 动态加载与动态交互 jscript
2.1 jscript.asp
2.2 ByFile.asp
2.3 ByString.asp
shawl.qiu
2007-09-15
http://blog.csdn.net/btbtd
下载:
http://files.myopera.com/btbtd/web/Jscript_Vbscript_dynamic_interaction_and_loading.7z
内容:
1. jscript 动态加载与动态交互 vbscript
1.1 vbscript.asp
Randomize
fRndNum=Int((iOver - iUnder + 1) * Rnd + iUnder)
end function 'fRndNum shawl.qiu code'
1.2 ByFile.asp
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>shawl.qiu template </title>
</head>
<body>
<%
var Ar = fStream("vbscript.asp", "utf-8", true);
//Response.Write("<xmp>"+Ar+"</xmp>");
function fStream(sPath, sCharset, bCov)
{ // shawl.qiu code, return array
if(bCov) sPath = Server.MapPath(sPath);
var Stream = new ActiveXObject("Adodb.Stream");
Stream.Type = 2;
Stream.Mode = 3;
Stream.Open;
Stream.LoadFromFile(sPath);
if(sCharset) Stream.CharSet = sCharset;
var iStep =0;
if(/utf/s*/-/s*8|unicode/i.test(sCharset)) iStep = 2;
Position = iStep;
var Ar = [Stream.ReadText()];
delete Stream;
return Ar;
} // end function fStream(sPath, sCharset)
fLoadingVbs(Ar[0]);
Response.Write(fRndNum(1, 10));
%>
<script runat="server" language="vbscript">
function fLoadingVbs(Ar)
ExecuteGlobal Ar
end function
</script>
</body>
</html>
1.3 ByString.asp
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>shawl.qiu template </title>
</head>
<body>
<%
var Ar = [
" function fRndNum(byval iUnder,byval iOver)/n"
," Randomize/n"
," fRndNum=Int((iOver - iUnder + 1) * Rnd + iUnder)/n"
," end function 'fRndNum shawl.qiu code'/n"
];
fLoadingVbs(Ar.join(""));
Response.Write(fRndNum(1, 10));
%>
<script runat="server" language="vbscript">
function fLoadingVbs(Ar)
ExecuteGlobal Ar
end function
</script>
</body>
</html>
2. vbscript 动态加载与动态交互 jscript
2.1 jscript.asp
{// shawl.qiu script, return Integer
switch(arguments.length)
{
case 1: return parseInt(Math.random()*iOver+1);
case 2: return parseInt(Math.random()*(iOver-iUnder+1) + iUnder);
default: return 0;
} // end switch
} // end function fRandomBy
2.2 ByFile.asp
<% option explicit %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>shawl.qiu template </title>
</head>
<body>
<%
Dim Str
Str = fRdTxFl("jscript.asp", "utf-8", true)
fLoadingJs "fRandomBy", Str
Response.Write(fRandomBy(1, 10))
private function fRdTxFl(byval sPath, byval sCharset, byval bCov)
if bCov then sPath=Server.MapPath(sPath)
dim oStm, sTemp
set oStm=createObject("adodb.stream")
with oStm
.Type=2
.Mode=3
.Open
.LoadFromFile sPath
.Charset=sCharset
.Position=0
fRdTxFl=.ReadText()
.Close
end with
set oStm=nothing
end function 'fRdTxFl shawl.qiu code'
%>
<script runat="server" language="jscript">
function fLoadingJs(sName, sCode)
{ // shawl.qiu code, void return
eval(sCode);
fExecuteGlobal(sName, eval(sName));
} // end function fLoadingJs(sName, sCode)
function fExecuteGlobal(sVar, Var)
{ // shawl.qiu code, void return
if(!sVar) throw new Error("var name must not empty!");
eval(sVar+"=Var");
} // function fExecuteGlobal(sVar, Var)
</script>
</body>
</html>
2.3 ByString.asp
<% option explicit %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>shawl.qiu template </title>
</head>
<body>
<%
Dim Str
Str = ""&VbCr&_
"function fRandomBy(iUnder, iOver)"&VbCr&_
"{// shawl.qiu script, return Integer"&VbCr&_
" switch(arguments.length)"&VbCr&_
" {"&VbCr&_
" case 1: return parseInt(Math.random()*iOver+1);"&VbCr&_
" case 2: return parseInt(Math.random()*(iOver-iUnder+1) + iUnder);"&VbCr&_
" default: return 0;"&VbCr&_
" } // end switch"&VbCr&_
"} // end function fRandomBy"&VbCr
fLoadingJs "fRandomBy", Str
Response.Write(fRandomBy(1, 10))
%>
<script runat="server" language="jscript">
function fLoadingJs(sName, sCode)
{ // shawl.qiu code, void return
eval(sCode);
fExecuteGlobal(sName, eval(sName));
} // end function fLoadingJs(sName, sCode)
function fExecuteGlobal(sVar, Var)
{ // shawl.qiu code, void return
if(!sVar) throw new Error("var name must not empty!");
eval(sVar+"=Var");
} // function fExecuteGlobal(sVar, Var)
</script>
</body>
</html>