|
|
|
|
|
Home
»
JavaScript
»
How to detect objects regardless of browsers types using java script
|
|
|
|
Author Rank :
|
|
|
Page Views :
|
2133
|
|
Downloads :
|
0
|
|
Rating :
|
Rate it
|
|
Level :
|
Beginner
|
|
|
Introduction
As we know, there are various kind of browsers used all over the world either by final users or by developers and this is the most used browsers list across the world according to Wikipedia encyclopedia 2008.
| Browser |
Frequency of use in percent |
| Internet explorer |
75.47 |
| Firefox |
16.98 |
| Safari |
5.82 |
| Opera |
0.62 |
| Netscape |
0.61 |
| Mozilla |
0.32 |
| Other |
0.17 | See: http://en.wikipedia.org/wiki/Comparison_of_web_browsers
The problem is that no all browsers support all java script technologies or they adopt them partially such as DOM (Document object model), ECMAScript, DHTML, XSLT, and the famous XMLHttpRequest object to build AJAX enabled client side applications. And here is the classification of browsers in term of technologies adoptions also from Wikipedia encyclopedia.
| Browser |
JavaScript |
ECMA |
DOM1 |
DOM2 |
DOM3 |
Xpath |
DHTML |
XMLHttpRequest |
| Internet Explorer |
yes |
yes |
partial |
no |
no |
yes |
yes |
yes |
| Firefox |
yes |
yes |
yes |
yes |
no |
yes |
yes |
yes |
| Safari |
yes |
yes |
yes |
yes |
partial |
yes |
yes |
yes |
| Opera |
yes |
yes |
yes |
yes |
partial |
yes |
yes |
yes |
| Netscape browser |
yes |
yes |
unknown |
unknown |
no |
unknown |
yes |
yes |
| Mozilla |
yes |
yes |
yes |
yes |
no |
yes |
yes |
yes | See: http://en.wikipedia.org/wiki/Comparison_of_web_browsers#JavaScript_support
So, how we can do to detect objects using JavaScript and at the same time considering that our application is designed to run not within all browsers but say almost browsers can run our scripts or at least tell the final user that some functionalities couldn't be used within his browser and give him a raison of such trouble.
Almost, all the JavaScript developers and experts didn't advice to implement browsers detector procedures within the script in order to decide witch technologies have to be used but to implement objects detector procedures instead. Now, if you have more that browser installed in your computer try this code.
<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Document sans nom</title>
<script language="javascript" type="text/javascript">
function Detect()
{
if(document.all)
{
alert("document.all supported by this browser");
}
else if(document.getElementById)
{
alert("document.getElementById supported by this browser"); } else if(document.layers) { alert("document.layers supported by this browser"); } else { alert("Your browser is either an older version or doesn't support javascript standard elements and functions");
}
} </script>
</head>
<body>
<input type="button" value="Click me" onclick="Detect();" />
</body>
</html> With this manner, we can implement for each Brower its corresponding fragment of code according to the technologies adopted, of Corse, so that the majority of users can enjoy our product without any problems or at least give them messages in case of troubles. I give a second example that I invite you to try it, of Corse, using more than one kind of browser:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Document sans nom</title>
<script language="javascript" type="text/javascript">
function WriteOnMySpan(id, sMessage)
{
if(document.all)
{
document.all[id].innerHTML = sMessage;
}
else if(document.getElementById)
{
document.getElementById(id).innerHTML = sMessage;
}
else if(document.layers)
{
document.all[id].innerHTML = sMessage;
}
else
{
alert("Your browser is either an older version or doesn't support javascript standard elements and functions");
}
}
</script>
</head>
<body>
<input type="button" value="Click me" onclick="WriteOnMySpan('mySpan', 'I \'m Bejaoui Bechir');" /><br />
<span id="mySpan" />
</body>
</html> Good JavaScripting!!!
|
|
Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post
Here.
|
|
|
|
|
Login
to add your contents and source code to this article
|
|
|
|
|
|
|
|
|
|
|
|
Bechir Bejaoui
The author holds a master degree in NTIC specialized in software developement delivered by the high school of communication SUPCOM, he also holds a bachelor degree in finance delivered by the economic sciences and management university of Tunis "FSEGT".
He also holds:
MCPD enteprise solutions developement 3.5 certification and MCTS distibuted application developement 2.0
He's a freelance developer since 2006. Actually woking on the WPF, .Net framewok 3.5, silverlight and the other .Net new features, in addition, he is painter and sculptor.
|
|
|
|
|
|
|
|
|
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional
consulting company, our consultants are well-known experts in .NET and many of them
are MVPs, authors, and trainers. We specialize in Microsoft .NET development and
utilize Agile Development and Extreme Programming practices to provide fast pace
quick turnaround results. Our software development model is a mix of Agile Development,
traditional SDLC, and Waterfall models.
|
|
Click here to learn more about C# Consulting. |
|
|
|
|
|
|
|
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon.
Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees.
As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
|
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
|
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
|
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites – Click Here!
|
|
|
|
|
|
|
|
|
|
|
|
|