HTML 5 enabling your web application
============================================There are several steps you need to take to ensure that your web application is ready for HTML 5. I am in the midst of a porting project from code that is
written specifically for IE 6 to make it HTML 5 enabled. Eventually this site should also be accessible on IPAD. I will list the steps to take and the things to watch out for. These are the steps and procedures that i am following.
The first thing is to decide on the DOCTYPE. DOCTYPE is the document type in browsers, this was introduced so that browsers can support different version
of HTML. Setting <!DOCTYPE html> will ensure that the browser will run in the latest mode and that is HTML 5.
Setting a DOCTYPE like <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> means that browser will run in standard mode and is an HTML 4.01 version. There are several other doctypes that you can set,
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
This tells modern browsers that you want to display your HTML 4.01 page in strict compliance with the DTD. These browsers will go into "strict" or
"standards" mode and render the page in compliance with the standards. So for example in this case using <FONT> element will not work as it is not w3c
compliant.
w3c is the governing body that defines the standards on HTML and what it does. When you set the DTD using the doctype it validates that the rendering is done as per the standard.
-----------------------------------
QUIRKS MODE
-----------------------------------
In IE, the rendering mode decides which box model it follows. In quirks mode it uses the traditional model, in strict mode the W3C model.
Doctype switching is the only way of selecting a box model in IE 6 Windows. Mozilla, Opera and IE Mac allow the use of the box-sizing declaration to select a box model, while Safari only supports the W3C box model.
See this site, it has more details:
http://www.quirksmode.org/css/quirksmode.html
-----------------------------------
Once you have set the doctype, make sure that the scripts , css are browser agnostic, now my current project the client has written code for IE 6 browser
and it is a 15 year old web application. To port something like this over here is a list of things to watch out for
1) window.event.keyCode is an IE only event property , to get it working on other browsers use
if(window.event)
keyPressed = window.event.keyCode; // IE
else
keyPressed = e.which; // Firefox
2) window.event.srcElement works only on safari, chrome and IE. The window.event.srcElement equivalent in firefox is window.event.target.
if (window.event) e = window.event;
var srcElement = e.srcElement? e.srcElement : e.target;
3) To get a custom attribute from an element, IE allows you to do something like this window.event.srcElement.mycustomAttrib , for a browser agnostic
version use e.target.attributes["ibID"].nodeValue
4) window.event.srcElement.innerText, innerText for a event srcElement works on chrome, IE and safar but on Firefox, you can use
window.event.srcElement.textContent
5) window.event.srcElement.parentElement does not work on firefox, use parentNode which is the DOM equivalent and will work on all browsers
6) IE will allow you to set custom attributes for elements for example: document.getElementById('mydiv').mycustomattr=55 , to get and set using DOM
properties use setAttribute and getAttribute.
7) The biggest headache is using the document.all.name and document.all(id). This is an IE only property, it is not possible to just do a find and replace
on this because the document.all works as both a name and id selector. To explain this further if there is a function that does something like
function replacedoc(idsearch)
{
var ele = document.all.idsearch;
......
Look for a certain element
}
The above function will take an id for the element to search and look at the entire DOM. The document.all returns an array containing all the scripts and
elements. Now to port this over to cross browser, you will have to know what it is you are looking for and how it is represented in the DOM tree. It is not
that simple as you need to spend time to figure that out.
Using JQUERY here as an equivalent, you will have to know the following
1. If a single element is fetched based on ID,
a) Use Jquery ID selector - ($('#id'))
document.all.SideMenu can be replaced with $('#SideMenu')
Check for Null references before using it
b) Use document.getElementById -
document.all.dlglst can be replaced with document.getElementById('dlglst')
2. If a single the element is fetched based on name, use name selector.
3. If it is of the form - "document.all." + name; where name is a parameter passed - THis queries by both name and ID, use "$(\"[name='" + name + "'], #" + name + "\")[0]"
Note $(jquery object)[0] returns the HTML element alone. the variable enclosed by $ contains the entire jquery object.
4. If multiple elements are fetched based on ID,
Document.all cannot be replaced with Jquery id selector in all scenarios because jquery id selector returns only the first element
http://api.jquery.com/id-selector/
- Each id value must be used only once within a document. If more than one element has been assigned the same ID, queries that use that ID will only select
the first matched element in the DOM. This behavior should not be relied on, however; a document with more than one element using the same ID is invalid
This happens if you have badly written HTML where multiple elements share the same ID and this very common in a lot of web applications.
5) Onpropertychange is a IE specific event and the equivalent is DOMATTRModified which works on all browser. This however does not work as IE. In IE the
onpropertychange is fired if an element property including its attributes are modified by script.
6) window.event.cancelBubble,
http://msdn.microsoft.com/en-us/library/ms533545(v=vs.85).aspx
http://javascript.about.com/od/byexample/a/events-cancelbubble-example.htm
http://www.quirksmode.org/js/events_order.html
Call the event’s stopPropagation() method.
function preventbubble(e)
{
if (e && e.stopPropagation) //if stopPropagation method supported
e.stopPropagation()
else
event.cancelBubble=true
}
Use the jquery StopPropogation method
7) document.body.parentElement.outerHTML , outerHTML is not supported on other browsers, use Jquery one for all browser
var x = jQuery.extend(jQuery.Event(e.type), e).target.cloneNode(true);
alert($(x).wrap('<div></div>').parent().html());"
8) createElement, this is a DOM property but what it accepts as its function parameter should be kept in mind. Only IE will accept and element with the
> and < tags.
var oIFrame = document.createElement('<IFRAME NAME=' + szName + ' CLASS=doAsyncIFrameClass>');
This should be replaced with
var oIFrame = document.createElement('IFRAME')
oIFrame.name = szName;
oIFrame.Class = 'doAsyncIFrameClass'; (Note case-sensitivity "Class" and not "class" works on safari-mac)
oIFrame.style.display = 'none';
9) document.scripts works only on IE , use document.getElementsByTagName('script')
----------------------------------------------------------------
JQUERY Beginnings
Good link to start learning JQUERY Jquery fundamentals--------------
Event with jQuery.event.fix
If you want to use the traditional HTML event binding and still use jQuery, here is a quick tip to get a “clean” (i.e. cross browsers) html event using jQuery.event.fix:<input type=”file” name=”photoFile” onchange=”upload(event)”/>
<script>
function upload(e){
var e = $.event.fix(e);
alert(”target: ” + e.target);
}
</script>
------------------------
How to add client capabilities to your web controls.
Click here to go to msdn site------------------------------------------------------------------------------------
What is a Identity Gap, watch the short video on Sql Share, Free site.
Click Here------------------------------------------------------------------------------------
IE BOX MODEL
IE 7 Onwards uses the W3C box model and other browser too. IE 6 uses the IE box model. The IE box model includes padding, border in its calculation of its width. The W3C model does not and calculates it separately. This is the main reason for alignment problems.IE box model, a box having a width of 100px, with 2px padding on each side, a 3px border, and 7px margin on each side, will have a visible width of 114px.
The W3C box model, excludes the padding and border from the width/height of an element. A box having a width of 100px, with 2px padding on each side, a 3px border, and 7px margin on each side, will have a visible width of 124px.
In order to make IE use the W3C box model (which is what every other browser uses), your page needs to be rendered in Strict mode. By default, IE renders in Quirks mode.
In order to trigger Strict mode in IE, you must specify a doctype. You can use any of the following doctypes:
HTML4 Strict:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd" >
XHTML 1.0 Strict:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
XHTML 1.0 Transitional:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Your doctype must be the first thing to appear on your page. It is even before the tag, on its own line. (Adding an prolog will cause IE to go back in Quirks mode, so remove it if you have one).
------------------------------------------------------------------------------------
C# USING keyword
The using keyword is used to define the scope of an object implementing the IDisposable interface.It automatically calls the Dispose() method when the object goes out of the scope defined in the using block.
This means that the developer need not call Dispose() method explicitly. All he needs to do is to define the scope of the object.
Here is an sample code snippet.
SqlConnection con = new SqlConnection();
using (con)
{
//your code goes here
}
USING keyword can be used only for those objects that implement the IDISPOSABLE interface.
----------------------------------------------------------------------------------
No comments:
Post a Comment