Wednesday, October 29, 2014

Disadvantages of JavaScript - YouTube

Published on Oct 29, 2014 Link for all dot net and sql server video tutorial playlists http://www.youtube.com/user/kudvenkat... Link for slides, code samples and text version of the video http://csharp-video-tutorials.blogspo... In this video we will discuss the disadvantages or downsides of using JavaScript. There are two main disadvantages of JavaScript. Security : JavaScript runs on the client machine. So a malicious user may use Javascript to do a variety of things like tracking your browsing history, stealing passwords etc. This is one of the main reasons why people disable JavaScript. Browser Compatibility : Not all browsers treat the same piece of JavaScript in the same manner. This means the functionality and the user interface may vary from browser to browser. That is why cross-browser testing is very important. However, with JavaScript libraries like jQuery Browser Compatibility is no longer a major issue. JavaScript Browser Compatibility Examples Example 1 : innerText property is supported in IE & Chrome, but not in Firefox. This means the ValidatForm() JavaScript function that we worked with in Part 1, will only work in IE & Chrome but not in Firefox. function ValidatForm() { var ret = true; if (document.getElementById("txtFirstN­ame").value == "") { document.getElementById("lblFirstNa­me").innerText = "First Name is required"; ret = false; } else { document.getElementById("lblFirstNa­me").innerText = ""; } if (document.getElementById("txtLastNa­me").value == "") { document.getElementById("lblLastNam­e").innerText = "Last Name is required"; ret = false; } else { document.getElementById("lblLastNam­e").innerText = ""; } if (document.getElementById("txtEmail&­quot;).value == "") { document.getElementById("lblEmail&q­uot;).innerText = "Email is required"; ret = false; } else { document.getElementById("lblEmail&q­uot;).innerText = ""; } return ret; } For the above JavaScript function to work in all the browsers that is in IE, Chrome & Firefox, replace innerText property with textContent as shown below. function ValidatForm() { var ret = true; if (document.getElementById("txtFirstN­ame").value == "") { document.getElementById("lblFirstNa­me").textContent = "First Name is required"; ret = false; } else { document.getElementById("lblFirstNa­me").textContent = ""; } if (document.getElementById("txtLastNa­me").value == "") { document.getElementById("lblLastNam­e").textContent = "Last Name is required"; ret = false; } else { document.getElementById("lblLastNam­e").textContent = ""; } if (document.getElementById("txtEmail&­quot;).value == "") { document.getElementById("lblEmail&q­uot;).textContent = "Email is required"; ret = false; } else { document.getElementById("lblEmail&q­uot;).textContent = ""; } return ret; } Example 2 : The following JavaScript function ddlGenderSelectionChanged() works in Chrome and Firefox but not in Internet Explorer. [%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="Demo.WebForm1" %] [!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml...] [html xmlns="http://www.w3.org/1999/xhtml"] [head runat="server"] [title][/title] [script type="text/javascript" language="javascript"] function ddlGenderSelectionChanged() { alert('You selected ' + ddlGender.value); } [/script] [/head] [body] [form id="form1" runat="server"] [div] [select id="ddlGender" onchange="ddlGenderSelectionChanged­()"] [option]Male[/option] [option]Female[/option] [/select] [/div] [/form] [/body] [/html] For the JavaScript function to work in all browsers (Chrome, Firefox & Internet Explorer) it needs to be modified as shown below. [script type="text/javascript" language="javascript"] function ddlGenderSelectionChanged() { alert('You selected ' + document.getElementById('ddlGender&#­39;).value); } [/script]

0 comments:

Post a Comment

Welcome to my Blog!
Bine ati venit pe blogul nostru.
Cand nu sunt pe blog calatorim!!!
When I'm not blogging, I'm traveling :-)

Email me atGuran

Search

Subscribeto this blog
Follow me onTwitter
Connect onFacebook
My Ello

Blogroll


© 2014 by Guran Cosmin.

You're welcome to link to this site or use a single image and brief description to link back to any post. Republishing posts in their entirety is prohibited without permission.

Pictures

Become a Fan

Find Us On Facebook

Contact Form

Name

Email *

Message *

Video

720x90 AdSpace

Recent Videos

Movie

http://youtu.be/Yj0G5UdBJZw
guran. Powered by Blogger.

Wikipedia

Search results

Popular Posts

Followers

Archive

wikiHow - Recent Changes [en]