JavaScript Tutorials - Herong's Tutorial Examples. JavaScript Tutorials - Herong's Tutorial Examples Copyright © 2013 by Dr. Herong Yang. All rights reserved. This free book is a collection of tutorial examples and notes written by the author while he was learning JavaScript. Topics include data type, variable, expression, statement, loop, user function, object, property, method, array, object, constructor, prototype. Table of Contents About This JavaScript Tutorial Example BookIntroduction to JavaScriptWhat Is JavaScript? Important guidelines. First let's learn some important stuff. There are lots of browsers out there that cannot support JavaScript.
Although browsers generally support more and more with each release, the language itself keeps evolving, and there is already a vast amount of the JavaScript language available for browsers to support. No browser will ever support all of it, and you cannot expect them to. There are many reasons why people cannot or will not 'upgrade' to your chosen browser. A few are: Whatever their reasons, you should not stop them from using your site. If your site uses JavaScript for navigation or content, then that navigation and content should be there without JavaScript enabled.
There are also many browsers out there that you do not realise exist. There is no magic formula for this, but the basic rules are that you should not detect a browser make or version. Learn How to Create a jQuery Plugin. You might think to yourself, "What is all the fuss with jQuery? You have to download a bunch of plugins to even make the library worth while. ". First, that isn't true. Second, the jQuery library was specifically designed for that very purpose.
By keeping the core library as small as possible - about 16 kb - users can then apply additional plugins at their own discretion. Today, I'll teach you how to build your first "Center" plugin from scratch. Let's get started! Our Objective We want to create a plugin that will dynamically adjust the styling of a specified element in order to keep it vertically and horizontally centered on the page at all times - even when the browser window is resized.
The Screencast Step 1 The first step when creating a plugin is to add a blank Javascript file. Step 2 Next, paste in the following code. I go into much greater detail in the video, however, I'd still like to go over a few key points. "Center" should be replaced with whatever your plugin's name is. Step 3. Cookies. Page last changed today See section 6G of the book. This script was originally written by Scott Andrew. Copied and edited by permission. This article has been translated into French On this page I give three functions to save, read and erase cookies. Using these functions you can manage cookies on your site. First an introduction to cookies, and a summary of document.cookie, followed by an example. Cookies Cookies were originally invented by Netscape to give 'memory' to web servers and browsers. This can be annoying in a number of ways. Cookies were invented to solve this problem.
A cookie is nothing but a small text file that's stored in your browser. A name-value pair containing the actual dataAn expiry date after which it is no longer validThe domain and path of the server it should be sent to As soon as you request a page from a server to which a cookie should be sent, the cookie is added to the HTTP header. Cookies can be read by JavaScript too. Each cookie also has a domain and a path. HttpOnly. Overview The goal of this section is to introduce, discuss, and provide language specific mitigation techniques for HttpOnly.
Who developed HttpOnly? When? According to a daily blog article by Jordan Wiens, “No cookie for you! ,” HttpOnly cookies were first implemented in 2002 by Microsoft Internet Explorer developers for Internet Explorer 6 SP1. Wiens, [1] What is HttpOnly? According to the Microsoft Developer Network, HttpOnly is an additional flag included in a Set-Cookie HTTP response header.
The example below shows the syntax used within the HTTP response header: Set-Cookie: <name>=<value>[; <Max-Age>=<age>] [; expires=<date>][; domain=<domain_name>] [; path=<some_path>][; secure][; HttpOnly] If the HttpOnly flag (optional) is included in the HTTP response header, the cookie cannot be accessed through client side script (again if the browser supports this flag). Mitigating the Most Common XSS attack using HttpOnly Using Java to Set HttpOnly Using .NET to Set HttpOnly Or programmatically. Login/session cookies, Ajax and security. Slicing arguments · dropshado.ws. In the jQuery Plugins Authoring tutorial, Ralph Holzmann details an intriguing pattern for plugin methods: var args = Array.prototype.slice.call( arguments, 1 );return methods[ method ].apply( this, args );// (edited for clarity) As the tutorial explains, this pattern is what enabled jQuery UI plugins to have multiple methods.
Indeed, If you look deep within the coils of jQuery UI widget factory, you’ll find it there as well: var args = slice.call( arguments, 1 );instance[ options ].apply( instance, args );// (again, edited for clarity) I had thought of this argument-slicing method pattern just as another bit of JavaScript witch-craft that seemed to work, but I had no comprehension of why. Today, I’m working on a sort of particle/field class and this pattern finally clicked. // field has multiple particlesfunction Field() { this.particles = []; for ( var i=0; i < max; i++ ) { this.particles.push( new Particle( i ) ); }} Particle.prototype.logIndex = function() { console.log( this.index );}