2025-04-27 07:49:33 -04:00

126 lines
5.2 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=Windows-1252">
<TITLE>Retrieving Browser Capabilities from a Cookie</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="Internet Information Services reference information">
<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">
<H2><A NAME="_retrieving_browser_capabilities_from_a_cookie"></A><SUP></SUP>Retrieving Browser Capabilities from a Cookie</H2>
<P>A new way of determining client capabilities was added in IIS 5.0. If the client sends a cookie describing their capabilities as part of the request, your ASP page can create an instance of the Browser Capabilities component that adds the name value pairs specified by the cookie as properties.</P>
<P>For example, if the client sent a cookie that contained a name-value pair of userLanguage=Spanish, the Browser Capabilities component would add a userLanguage property and set the value for this property to Spanish. </P>
<P><span class=le><B>Important</B></span></P>
<P>If the METADATA#metatag exists in a file that is requested by the client as a result of a redirection using the <A HREF="/iishelp/iis/htm/asp/vbob9waa.htm">Server.Transfer</A> or <A HREF="/iishelp/iis/htm/asp/vbob9pid.htm">Server.Execute</A> methods, the metatag will be ignored by IIS. METADATA metatags in the file that actually contains the redirect, however, will be processed normally.</P>
<P>The following example demonstrates using a cookie to determine browser capabilities. Two files are required:
<UL type=disc>
<LI>Sendcook.htm runs on the client and uses DHTML to determine a list of properties that have been set on the client.</li>
<LI>Checkcap.asp creates an instance of the Browser Capabilities component and retrieves the properties from Sendcook.htm.</li>
</UL>
<P>--- SendCook.htm ---</P>
<PRE><CODE>&lt;HTML&gt;
&lt;HEAD&gt;
&lt;SCRIPT language="JavaScript"&gt;
function stopAllErrors()
{
// No errors should be presented to the user if they occur.
return true;
}
window.onerror = stopAllErrors;
function window.onload ()
{
oClientCaps.style.behavior = "url(#default#clientCaps)";
bcString = "width= " + oClientCaps.width;
bcString += "&amp;height= " + oClientCaps.height;
bcString += "&amp;bufferDepth= " + oClientCaps.bufferDepth;
bcString += "&amp;colorDepth= " + oClientCaps.colorDepth;
bcString += "&amp;cookies= " + oClientCaps.cookieEnabled;
bcString += "&amp;platform= " + oClientCaps.platform;
document.cookie = "BrowsCap= " + bcString;
}
&lt;/SCRIPT&gt;
&lt;/HEAD&gt;
&lt;BODY ID="oClientCaps"&gt;
&lt;/BODY&gt;
&lt;/HTML&gt;
</CODE></PRE>
<P>--- CheckCap.asp ---</P>
<PRE><CODE>&lt;!--METADATA TYPE="Cookie" NAME="BrowsCap" SRC="sendcook.htm"--&gt;
&lt;HTML&gt;
&lt;BODY&gt;
&lt;% Set myBrowsCap = Server.CreateObject("MSWC.BrowserType") %&gt;
&lt;%
Response.write("width= " +myBrowsCap.width + "&lt;BR&gt;")
Response.write("height= " +myBrowsCap.height + "&lt;BR&gt;")
Response.write("bufferDepth= " +myBrowsCap.bufferDepth + "&lt;BR&gt;")
Response.write("colorDepth= " +myBrowsCap.colorDepth + "&lt;BR&gt;")
Response.write("cookies= " +CStr(myBrowsCap.cookies) + "&lt;BR&gt;")
Response.write("platform= " +myBrowsCap.platform + "&lt;BR&gt;")
%&gt;
&lt;/BODY&gt;
&lt;/HTML&gt;
</CODE></PRE>
<P>For more information on the design implications for determining browser capabilities, see <A HREF="/iishelp/iis/htm/asp/eadg6isz.htm">Client Capabilities</A>.</P>
<hr class="iis" size="1">
<p align="center"><em><a href="../../../common/colegal.htm">&copy; 1997-2001 Microsoft Corporation. All rights reserved.</a></em></p>
</BODY>
</HTML>