⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 js_browser.asp@output=print

📁 W3Schools tutorial..web designing
💻 ASP@OUTPUT=PRINT
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-US" xml:lang="en-US" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>JavaScript Browser Detection</title>
 
<link rel="shortcut icon" href="../favicon.ico" type="image/x-icon" />
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<meta name="Keywords" content="xml,tutorial,html,dhtml,css,xsl,xhtml,javascript,asp,ado,vbscript,dom,sql,colors,soap,php,authoring,programming,training,learning,beginner's guide,primer,lessons,school,howto,reference,examples,samples,source code,tags,demos,tips,links,FAQ,tag list,forms,frames,color table,w3c,cascading style sheets,active server pages,dynamic html,internet,database,development,Web building,Webmaster,html guide" />

<meta name="Description" content="Free HTML XHTML CSS JavaScript DHTML XML DOM XSL XSLT RSS AJAX ASP ADO PHP SQL tutorials, references, examples for web building." />

<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="cache-control" content="no-cache" />

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "../../https@ssl./default.htm" : "../../www./default.htm");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-3855518-1");
pageTracker._initData();
pageTracker._trackPageview();
</script>

</head>
<body>

<p>From <b>http://www.w3schools.com</b> (Copyright Refsnes Data)</p>

<h1>JavaScript Browser Detection</h1>
<a href="js_obj_htmldom.asp"><img alt="previous" border="0" src="../images/btn_previous.gif" width="100" height="20" /></a>
<a href="js_cookies.asp"><img alt="next" border="0" src="../images/btn_next.gif" width="100" height="20" /></a>
<hr />
<p class="intro">The JavaScript Navigator object contains information about the 
visitor's browser.</p>
<hr />

<h2>Examples</h2>
<p><a target="_blank" href="tryit.asp@filename=tryjs_browser">Detect the visitor's browser and browser version</a></p>
<p><a target="_blank" href="tryit.asp@filename=tryjs_browserdetails">More details about the visitor's browser</a></p>
<p><a target="_blank" href="tryit.asp@filename=try_dom_navigator">All details about the visitor's browser</a></p>
<p><a target="_blank" href="tryit.asp@filename=tryjs_browser2">Alert user, depending on browser</a></p>
<hr />

<h2>Browser Detection</h2>
<p>Almost everything in this tutorial works on all JavaScript-enabled browsers. 
However, there are some things that just don't work on certain browsers - specially 
on older browsers.</p>
<p>So, sometimes it can be very useful to detect the visitor's browser type and 
version, and then serve up the appropriate information.</p>
<p>The best way to do this is to make your web pages smart enough to look one 
way to some browsers and another way to other browsers.</p>
<p>JavaScript includes an object called the Navigator object, that can be used 
for this purpose.</p>
<p>The Navigator object contains information about the visitor's browser name, 
browser version, and more.</p>
<hr />

<h2>The Navigator Object</h2>
<p>The JavaScript Navigator object contains all information about the 
visitor's browser. We are going to look at two properties of the Navigator 
object:</p>
<ul>
	<li>appName -&nbsp; holds the name of the browser</li>
	<li>appVersion - holds, among other things, the version of the browser</li>
</ul>
<h3>Example</h3>
<table class="ex" cellspacing="0" border="1" width="100%" id="table2"><tr><td>
<pre>&lt;html&gt;</pre>
<pre>&lt;body&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
var browser=navigator.appName;
var b_version=navigator.appVersion;
var version=parseFloat(b_version);</pre>
<pre>document.write(&quot;Browser name: &quot;+ browser);
document.write(&quot;&lt;br /&gt;&quot;);
document.write(&quot;Browser version: &quot;+ version);
&lt;/script&gt;
&lt;/body&gt;</pre>
<pre>&lt;/html&gt;</pre>
</td></tr></table>
<p>The variable browser in the example above holds the name of the browser, i.e. &quot;Netscape&quot; 
or 
&quot;Microsoft Internet Explorer&quot;.</p>
<p>The appVersion property in the example above returns a string that contains much more information 
than just the version number, but for now we are only interested in the version 
number. To pull 
the version number out of the string we are using a function called parseFloat(), 
which pulls the first thing that looks like a decimal number out of a string and 
returns it.</p>
<p><b>IMPORTANT!</b> The version number is WRONG in IE 5.0 or later! Microsoft 
starts the appVersion string with the number 4.0. in IE 5.0 and IE 6.0!!! 
Why did they do that??? However, JavaScript is the same in IE6, IE5 and IE4, so 
for most scripts it is ok.</p>
<h3>Example</h3>
<p>The script below displays a different alert, depending on the visitor's 
browser:</p>
<table class="ex" cellspacing="0" border="1" width="100%" id="table3"><tr><td>
<pre>&lt;html&gt;
&lt;head&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
function detectBrowser()<br />{<br />var browser=navigator.appName;
var b_version=navigator.appVersion;
var version=parseFloat(b_version);
if ((browser==&quot;Netscape&quot;||browser==&quot;Microsoft Internet Explorer&quot;)
&amp;&amp; (version&gt;=4))<br />{
alert(&quot;Your browser is good enough!&quot;);
}
else
{
alert(&quot;It's time to upgrade your browser!&quot;);
}<br />}
&lt;/script&gt;
&lt;/head&gt;</pre>
<pre>&lt;body onload=&quot;detectBrowser()&quot;&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
</td></tr></table>
<br />
<hr />
<a href="js_obj_htmldom.asp"><img alt="previous" border="0" src="../images/btn_previous.gif" width="100" height="20" /></a>
<a href="js_cookies.asp"><img alt="next" border="0" src="../images/btn_next.gif" width="100" height="20" /></a>

<p>From <b>http://www.w3schools.com</b> (Copyright Refsnes Data)</p>

</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -