Monday, April 13, 2015
A lot of you may have wonder why JQuery releases versions 1.x and 2.x, the reason is because the 1.x versions are released to support older versions of Internet Explorer. What a lot of people don't realize is that the 2.x version performs better, so if you have the choice between 1.x and 2.x you should choose the 2.x versions. Use the 1.x versions only if you have to. In this blog we will show how to use conditional comments which Microsoft created in Internet Explorer 5. Since it's specifically created for Internet Explorer other browsers will ignore it. Since Internet Explorer 9 seems to be the divider for support we will use it as the base case for our conditional comments. Here is the code to use the conditional comments to support older versions of Internet Explorer.
The code above uses the 1.x if the browser the user is using is older than Internet Explorer 9, and uses the 2.x if the Internet Explorer is greater than Internet Explorer. The important thing to note is the conditional part of the markup [if lt IE 9] says that if browser is "lt" (less than) IE 9. Load JQuery 1.x version. The same is true for the other condition [if gte IE 9] says that if the browser is "gte" (greater than or equal to) IE 9 then load the version 2.x.
Now let's add some JQuery to display the version of JQuery the browser is using, unfortunately I don't have a browser that is older than Internet Explorer 9, but a lot of your users will because of Windows XP. So since I am using Internet Explorer 11, I should be getting the message that says I am using a 2.x version of JQuery because my browser version is gte IE 9:
If you run the code above an alert message will pop-up with the JQuery version.
<html <head> <meta charset="utf-8" /> <title>JQuery Conditional Comments Demo</title> <!-- [if lt IE 9]> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> <![endif]--> <!--[if gte IE 9]><!--> <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <!--<![endif]--> </head> <body> </body> </html>
The code above uses the 1.x if the browser the user is using is older than Internet Explorer 9, and uses the 2.x if the Internet Explorer is greater than Internet Explorer. The important thing to note is the conditional part of the markup [if lt IE 9] says that if browser is "lt" (less than) IE 9. Load JQuery 1.x version. The same is true for the other condition [if gte IE 9] says that if the browser is "gte" (greater than or equal to) IE 9 then load the version 2.x.
Now let's add some JQuery to display the version of JQuery the browser is using, unfortunately I don't have a browser that is older than Internet Explorer 9, but a lot of your users will because of Windows XP. So since I am using Internet Explorer 11, I should be getting the message that says I am using a 2.x version of JQuery because my browser version is gte IE 9:
<html <head> <meta charset="utf-8" /> <title>JQuery Conditional Comments Demo</title> <!-- [if lt IE 9]> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> <![endif]--> <!--[if gte IE 9]><!--> <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <!--<![endif]--> <script type="text/javascript"> $(document).ready(function(){ alert("JQuery Version: " + $.fn.jquery); }); </script> </head> <body> </body> </html>
If you run the code above an alert message will pop-up with the JQuery version.
Subscribe to:
Post Comments (Atom)
Search This Blog
Tags
Web Development
Linux
Javascript
DATA
CentOS
ASPNET
SQL Server
Cloud Computing
ASP.NET Core
ASP.NET MVC
SQL
Virtualization
AWS
Database
ADO.NET
AngularJS
C#
CSS
EC2
Iaas
System Administrator
Azure
Computer Programming
JQuery
Coding
ASP.NET MVC 5
Entity Framework Core
Web Design
Infrastructure
Networking
Visual Studio
Errors
T-SQL
Ubuntu
Stored Procedures
ACME Bank
Bootstrap
Computer Networking
Entity Framework
Load Balancer
MongoDB
NoSQL
Node.js
Oracle
VirtualBox
Container
Docker
Fedora
Java
Source Control
git
ExpressJS
MySQL
NuGet
Blogger
Blogging
Bower.js
Data Science
JSON
JavaEE
Web Api
DBMS
DevOps
HTML5
MVC
SPA
Storage
github
AJAX
Big Data
Design Pattern
Eclipse IDE
Elastic IP
GIMP
Graphics Design
Heroku
Linux Mint
Postman
R
SSL
Security
Visual Studio Code
ASP.NET MVC 4
CLI
Linux Commands
Powershell
Python
Server
Software Development
Subnets
Telerik
VPC
Windows Server 2016
angular-seed
font-awesome
log4net
servlets
tomcat
AWS CloudWatch
Active Directory
Angular
Blockchain
Collections
Compatibility
Cryptocurrency
DIgital Life
DNS
Downloads
Google Blogger
Google Chrome
Google Fonts
Hadoop
IAM
KnockoutJS
LINQ
Linux Performance
Logging
Mobile-First
Open Source
Prototype
R Programming
Responsive
Route 53
S3
SELinux
Software
Unix
View
Web Forms
WildFly
XML
cshtml
githu
Aivivu - đại lý chuyên vé máy bay trong nước và quốc tế
ReplyDeletesăn vé máy bay giá rẻ đi Mỹ
vé máy bay từ mỹ về việt nam mùa dịch
giá vé máy bay từ canada về Việt Nam
chuyến bay nhật bản về việt nam
Lịch bay từ Seoul đến Hà Nội
Vé máy bay từ Đài Loan về VN
chuyen bay danh cho chuyen gia