129 lines
4.4 KiB
HTML
129 lines
4.4 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
|
|
<html dir=ltr><head><title>Interacting with Client-Side Scripts</title>
|
|
|
|
<SCRIPT LANGUAGE="JavaScript">
|
|
<!--
|
|
TempString = navigator.appVersion
|
|
if (navigator.appName == "Microsoft Internet Explorer"){
|
|
// Check to see if browser is Microsoft
|
|
if (TempString.indexOf ("4.") >= 0){
|
|
// Check to see if it is IE 4
|
|
document.writeln('<link rel="stylesheet" type="text/css" href="/iishelp/common/coua.css">');
|
|
}
|
|
else {
|
|
document.writeln('<link rel="stylesheet" type="text/css" href="/iishelp/common/cocss.css">');
|
|
}
|
|
}
|
|
else if (navigator.appName == "Netscape") {
|
|
// Check to see if browser is Netscape
|
|
document.writeln('<link rel="stylesheet" type="text/css" href="/iishelp/common/coua.css">');
|
|
}
|
|
else
|
|
document.writeln('<link rel="stylesheet" type="text/css" href="/iishelp/common/cocss.css">');
|
|
//-->
|
|
</script>
|
|
|
|
|
|
|
|
<SCRIPT LANGUAGE="VBScript">
|
|
<!--
|
|
Sub Window_OnLoad()
|
|
Dim frmContents
|
|
On Error Resume Next
|
|
If Not Parent Is Nothing Then
|
|
Set frmContents = Parent.Contents
|
|
If Not frmContents Is Nothing Then
|
|
frmContents.Window.TOCSynch_Click
|
|
End If
|
|
End If
|
|
End Sub
|
|
//--></SCRIPT>
|
|
|
|
<META NAME="DESCRIPTION" CONTENT="Procedural information on how to use ASP to generate client-side scripts that are processed by the client browser. You can write server-side scripts that put together script commands that are sent to the browser."><META HTTP-EQUIV="Content-Type" content="text/html; charset=Windows-1252">
|
|
<META HTTP-EQUIV="PICS-Label" CONTENT='(PICS-1.1 "<http://www.rsac.org/ratingsv01.html>" l comment "RSACi North America Server" by "inet@microsoft.com <mailto:inet@microsoft.com>" r (n 0 s 0 v 0 l 0))'>
|
|
<META NAME="MS.LOCALE" CONTENT="EN-US">
|
|
<META NAME="MS-IT-LOC" Content="Internet Information Services">
|
|
|
|
</head>
|
|
|
|
<body bgcolor="#FFFFFF" text="#000000"><font face="Verdana,Arial,Helvetica">
|
|
|
|
<h1><a name="H1_37766214">Interacting with Client-Side Scripts</a></h1>
|
|
|
|
|
|
<p>ASP's effectiveness can be extended by using it to generate or manipulate client-side scripts. For example, you can write server-side scripts that assemble client-side scripts based on server-specific variables, a user's browser type, or HTTP request parameters.</p>
|
|
|
|
<p>By interspersing server-side script statements within client-side scripts (enclosed by HTML <SCRIPT> tags), as shown in the following example template, you can dynamically initialize and alter client-side scripts at the request time:</p>
|
|
|
|
<pre><SCRIPT LANGUAGE="VBScript">
|
|
<!--
|
|
|
|
<EM>variable</EM> = <%=<Em>server defined value</Em> %>
|
|
.
|
|
.
|
|
.
|
|
|
|
<Em>client-side script</Em>
|
|
|
|
<% <Em>server-side script used to generate a client-side statement</Em> %>
|
|
|
|
<Em>client-side script</Em>
|
|
.
|
|
.
|
|
.
|
|
-->
|
|
</SCRIPT></pre>
|
|
|
|
<p>Incorporating such functionality can produce some useful and interesting applications. For example, the following is a simple server-side script (written in VBScript) that manipulates a client-side script (written in JScript):</p>
|
|
|
|
<pre><%
|
|
Dim dtmTime, strServerName, strServerSoftware, intGreeting
|
|
|
|
dtmTime = Time()
|
|
strServerName = Request.ServerVariables("SERVER_NAME")
|
|
strServerSoftware = Request.ServerVariables("SERVER_SOFTWARE")
|
|
|
|
'Generate a random number.
|
|
Randomize
|
|
intGreeting = int(rnd * 3)
|
|
%>
|
|
|
|
<SCRIPT LANGUAGE="JScript">
|
|
<!--
|
|
|
|
//Call function to display greeting
|
|
showIntroMsg()
|
|
|
|
function showIntroMsg()
|
|
{
|
|
switch(<%= intGreeting %>)
|
|
{
|
|
case 0:
|
|
msg = "This is the <%= strServerName%> Web server running <%= strServerSoftware %>."
|
|
break
|
|
case 1:
|
|
msg = "Welcome to the <%= strServerName%> Web server. The local time is <%= dtmTime %>."
|
|
break
|
|
case 2:
|
|
msg = "This server is running <%= strServerSoftware %>."
|
|
break
|
|
}
|
|
|
|
document.write(msg)
|
|
|
|
}
|
|
|
|
-->
|
|
</SCRIPT>
|
|
</pre>
|
|
|
|
<p>Scripts of this kind can be expanded, for example, to configure a client-side database or a DHTML personalization script. Innovative use of this technique can also reduce round-trips and server processing.</p>
|
|
|
|
|
|
<hr class="iis" size="1">
|
|
<p align="center"><em><a href="/iishelp/common/colegal.htm">© 1997-2001 Microsoft Corporation. All rights reserved.</a></em></p>
|
|
|
|
</font>
|
|
</body>
|
|
</html>
|