Tag » Posts Tagged ‘Javascript’

How to use cookies in JavaScript?

A Cookie is a piece of information that is stored locally on users browser and is sent with each HTTP request to the server. HTTP being a stateless protocol, cookies provide a mechanism by which we can remember user preferences and share information between web pages.

The cookies have a limit of 4KB thus when this limit is reached, you will likely be unable to create a new cookie. To make it more clear, size of all cookies under a specific domain cannot exceed 4KB.

Continue reading »

JSON – An Overview

JSON

JSON stands for JavaScript Object Notation. It is a format for storing and exchanging data. It is based on a subset of the JavaScript Programming Language.

The file type for JSON files is “.json” and MIME type for JSON text is “application/json“.

Here are the characteristics of JSON:

  1. It is a lightweight data-interchange format.
  2. It is easy for humans to understand.
  3. It uses Javascript format but it is a text which makes it is completly language independent as text can be read and parsed by any programmng language.

Continue reading »

How to move the JS file includes to footer in Magento

Magento

In order to reduce the initial load time of page, it is recommended to move all the JS includes in the <head> section of web page to the footer. Lets see how we can do it in Magento.

Step 1: Add Layout Updates

Create a child block of “before_body_end” named “foot” similar to the head block in local.xml file as shown below:

<?xml version="1.0" ?>
<layout version="0.1.0">
<default>
<reference name="before_body_end">
<block type="page/html_head" name="foot" as="foot" after="-" template="page/html/foot.phtml"/>
</reference>
</default>
</layout>

Continue reading »

How to limit the number of characters that can be entered in a textarea or input field?

Edit Text

In web pages which take input/feedback from the customers it’s a good idea to limit the type and size of data that can be entered so that spam can be avoided.

Let see how we can limit the number of characters that can be entered in a text box.

The simplest approach I follow is to use the jQuery “Limit” plugin. Click here to download the plugin.

Continue reading »

Back to top