Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

129 lines (129 sloc) 5.256 kb
<?xml version="1.0"?>
<entries>
<entry type="property" name="jQuery.browser" return="Map">
<title>jQuery.browser</title>
<signature>
<added>1.0</added>
</signature>
<desc><![CDATA[Contains flags for the useragent, read from navigator.userAgent. <strong>We recommend against using this property; please try to use feature detection instead (see jQuery.support). jQuery.browser may be moved to a plugin in a future release of jQuery.</strong> ]]></desc>
<longdesc>
<p>The <code>$.browser</code> property provides information about the web browser that is accessing the page, as reported by the browser itself. It contains flags for each of the four most prevalent browser classes (Internet Explorer, Mozilla, Webkit, and Opera) as well as version information.</p>
<p>Available flags are:</p>
<ul>
<li>webkit (as of jQuery 1.4)</li>
<li>safari (deprecated)</li>
<li>opera</li>
<li>msie</li>
<li>mozilla</li>
</ul>
<p>This property is available immediately. It is therefore safe to use it to determine whether or not to call <code>$(document).ready()</code>.
The <code>$.browser</code> property is deprecated in jQuery 1.3, and its functionality may be moved to a team-supported plugin in a future release of jQuery.</p>
<p>Because <code>$.browser</code> uses <code>navigator.userAgent</code> to determine the platform, it is vulnerable to spoofing by the user or misrepresentation by the browser itself. It is always best to avoid browser-specific code entirely where possible. The <code><a href="http://api.jquery.com/jQuery.support/">$.support</a></code> property is available for detection of support for particular features rather than relying on <code>$.browser</code>. </p>
</longdesc>
<example>
<desc>Show the browser info.</desc>
<code><![CDATA[
jQuery.each(jQuery.browser, function(i, val) {
$("<div>" + i + " : <span>" + val + "</span>")
.appendTo( document.body );
});]]></code>
<css><![CDATA[
p { color:green; font-weight:bolder; margin:3px 0 0 10px; }
div { color:blue; margin-left:20px; font-size:14px; }
span { color:red; }
]]></css>
<html><![CDATA[
<p>Browser info:</p>
]]></html>
</example>
<example>
<desc>Returns true if the current useragent is some version of Microsoft's Internet Explorer.</desc>
<code><![CDATA[
$.browser.msie;
]]></code>
</example>
<example>
<desc>Alerts "this is WebKit!" only for WebKit browsers</desc>
<code><![CDATA[
if ($.browser.webkit) {
alert( "this is webkit!" );
}
]]></code>
</example>
<example>
<desc>Alerts "Do stuff for Firefox 3" only for Firefox 3 browsers.</desc>
<code><![CDATA[
var ua = $.browser;
if ( ua.mozilla && ua.version.slice(0,3) == "1.9" ) {
alert( "Do stuff for firefox 3" );
}
]]></code>
</example>
<example>
<desc>Set a CSS property that's specific to a particular browser.</desc>
<code><![CDATA[
if ( $.browser.msie ) {
$("#div ul li").css( "display","inline" );
} else {
$("#div ul li").css( "display","inline-table" );
}
]]></code>
</example>
<category slug="deprecated"/>
<category slug="properties/global-jquery-object-properties"/>
<category slug="utilities"/>
<category slug="version/1.0"/>
<category slug="version/1.1.3"/>
</entry>
<entry type="property" name="jQuery.browser.version" return="String">
<signature>
<added>1.1.3</added>
</signature>
<desc>The version number of the rendering engine for the user's browser.</desc>
<longdesc>
<p>Here are some typical results:</p>
<ul>
<li>Internet Explorer: 6.0, 7.0, 8.0</li>
<li>Mozilla/Firefox/Flock/Camino: 1.7.12, 1.8.1.3, 1.9</li>
<li>Opera: 10.06, 11.01</li>
<li>Safari/Webkit: 312.8, 418.9</li>
</ul>
<p>Note that IE8 claims to be 7 in Compatibility View.</p>
</longdesc>
<example>
<desc>Returns the version number of the rendering engine used by the user's current browser. For example, FireFox 4 returns 2.0 (the version of the Gecko rendering engine it utilizes).</desc>
<code><![CDATA[
$("p").html( "The version number of the rendering engine your browser uses is: <span>" +
$.browser.version + "</span>" );
]]></code>
<css><![CDATA[
p { color:blue; margin:20px; }
span { color:red; }
]]></css>
<html><![CDATA[
<p></p>
]]></html>
</example>
<example>
<desc>Alerts the version of IE's rendering engine that is being used:</desc>
<code><![CDATA[
if ( $.browser.msie ) {
alert( $.browser.version );
}
]]></code>
</example>
<example>
<desc>Often you only care about the "major number," the whole number, which you can get by using JavaScript's built-in <code>parseInt()</code> function:</desc>
<code><![CDATA[
if ( $.browser.msie ) {
alert( parseInt($.browser.version, 10) );
}
]]></code>
</example>
<category slug="deprecated"/>
<category slug="properties/global-jquery-object-properties"/>
<category slug="utilities"/>
<category slug="version/1.0"/>
<category slug="version/1.1.3"/>
</entry>
</entries>
Jump to Line
Something went wrong with that request. Please try again.