Wednesday 9 April 2014

jQuery - Events Handling

jQuery - Events Handling


We have the ability to create dynamic web pages by using events. Events are actions that can be detected by your Web Application.
Following are the examples events:
  • A mouse click
  • A web page loading
  • Taking mouse over an element
  • Submitting an HTML form
  • A keystroke on your keyboard
  • etc.
When these events are triggered you can then use a custom function to do pretty much whatever you want with the event. These custom functions call Event Handlers.

Binding event handlers:

Using the jQuery Event Model, we can establish event handlers on DOM elements with the bind()method as follows:
$('div').bind('click', function( event ){
   alert('Hi there!');
});
This code will cause the division element to respond to the click event; when a user clicks inside this division thereafter, the alert will be shown. 
The full syntax of the bind() command is as follows:
selector.bind( eventType[, eventData], handler)

jQuery Slide Effect

jQuery Slide Effect


The Slide effect can be used with show/hide/toggle. 


Here is the simple syntax to use this effect:
selector.hide|show|toggle( "slide", {arguments}, speed );

Parameters:

Here is the description of all the arguments:
  • direction: The direction of the effect. Can be "left", "right", "up", "down". Default is left.
  • distance: The distance of the effect. Is set to either the height or width of the element depending on the direction option.
  • mode: The mode of the effect. Can be "show" or "hide". Default is show.

Example:

Following is a simple example a simple showing the usage of this effect:
<html>
<head>
<title>the title</title>
   <script type="text/javascript" 
   src="/jquery/jquery-1.3.2.min.js"></script>
   <script type="text/javascript" 
   src="/jquery/jquery-ui-1.7.2.custom.min.js"></script>
   <script type="text/javascript" language="javascript">
   
    $(document).ready(function() {

      $("#hide").click(function(){
         $(".target").hide( "slide", 
                     { direction: "down"  }, 2000 );
      });

      $("#show").click(function(){
         $(".target").show( "slide", 
                      {direction: "up" }, 2000 );
      });

   });
   </script>
   <style>
      p {
           background-color:#bca;
           width:200px; 
           border:1px solid green; 
        }
     div{ width:100px; 
            height:100px; 
            background:red;  
        }
  </style>
</head>
<body>

   <p>Click on any of the buttons</p>
   <button id="hide"> Hide </button>
   <button id="show"> Show</button> 
  
   <div class="target">
   </div>
  
</body>
</html>

How to Get mouse position using jquery


Get mouse cursor x and y axis

This script will display the x and y value – the coordinate of the mouse pointer.
$().mousemove(function(e){
    //display the x and y axis values inside the P element
    $('p').html("X Axis : " + e.pageX + " | Y Axis " + e.pageY);
});
<p></p> 

how to Disable right-click



Disable right-click contextual menu

There’s many Javascript snippets available to disable right-click contextual menu, but JQuery makes things a lot easier:
$(document).ready(function(){
    $(document).bind("contextmenu",function(e){
        return false;
    });
});

Tuesday 8 April 2014

How to make website to appear on search engine's first page

Increase visibility on search engine
You can get high rankings and increase web traffic to your site by doing the following steps.  Not following our advice on any tip will result in lower rankings on some search engines.  Please contact us if you need to know "the why" to the below statements:
  • research what keywords people use most often on search engines that pertain to your products or services;  use these keywords as text in the design to increase website traffic.
  • "Keep It Simple" - 99% of all web designers use too many graphical images and programs like Java, Flash, etc. which results in lower rankings and less traffic..
  • Web pages, like a spread sheet, are made using cells and tables.  Use as few cells and tables in your web design as possible.
  • Create good Meta Tags.  Each page should have different keywords in the Title and the Description Meta Tag.
  • Limit the number of times that you repeat words in your Keyword Meta Tag.
  • Place your important keywords at the top of the page as text headers.
  • Your most important page and keywords should be on the first page of a website.
  • Frames based websites should only be used for Intranet (a site only for company employees) and not for Internet.
  • Do NOT include pages that re-direct (a page that automatically sends you to another page) people to other pages.
  • Run an analysis program to count the number of times keywords are used in the first 7500 characters of computer code.
  • Limit your use of services that automatically submits your URL to the top 10 search engines.
  • When finished with a page, run a spell checking program and then compress the html code.
  • Keep track of your search engine rankings and website traffic.
  • Once a website is indexed, a good web designer should go back and improve pages that didn't get high rankings on key words.
  • Every 3 months you should make a small change on each web page.  Search engines like to see that changes are being made to a site and that it just isn't sitting there for years with no upgrades.

How to change the Magento Admin URL

How to change the Magento Admin URL / Path

To protect your Magento backend against hackers and brute-force attacks, we recommend that you change the default URL to the Magento Admin Panel. It is a quick way to add an extra layer of security to your site.
Follow these steps to change the admin URL/path.
Note: Do NOT use the web interface in the Magento Admin Panel to change the admin URL, as this is known to cause severe problems.

Step 1 - Change Path

First, open the local.xml configuration file in your favorite text editor, or use the Text Editor in the cPanel File Manager. The file is usually located in the app/etc/ directory under your Magento installation. Locate the following code segment:
  1. <admin>
  2.   <routers>
  3.     <adminhtml>
  4.       <args>
  5.         <frontName><![CDATA[admin]]></frontName>
  6.       </args>
  7.     </adminhtml>
  8.   </routers>
  9. </admin>
Now, replace admin with your new admin path. This should be something personal which is hard to guess, use only letters or numbers - no special characters, then save the file.

Step 2 - Refresh Cache

The final step is to refresh your cache. Use an FTP client to delete the content of the var/cache/ directory, or use the following SSH command.
(First, navigate to you Magento root directory)
  1. rm -rf var/cache/*

Step 3 - Complete

The change is now complete and you should try to log in via the new admin url - http://yourmagentodomain/adminpath/, replacing 'adminpath' with the path you chose in the step above. If everything went fine, you should now be presented with the Admin Panel login screen at the new URL. The old admin login URL should return a 404 error message.

How to Install Magento on Localhost

Installing Magento on Localhost


Installing Magento on WAMP can be pretty painful for beginners, as magento requires a lot of server configurations which are not set by default.
*For those who are wondering, Why a server ? Well, for running a website you have to host the site in any server so that people in the internet can find it. In this case you will be turning your computer into a server and will host your website in it, so that you can see how your website behaves. But in this case your website will open only from the server i.e. your local computer.
Before you start installing you need the following:
1. WAMP server installed in your computer
2. Magento Community Edition Files.
If you don’t have WAMP installed in your computer, then follow as explained below:

Installing WAMP:

  1. Download WAMP from http://www.wampserver.com/en/.
  2. Install and start the WAMP server.

    wamp-icon
  3. Make sure that your wamp icon is green, if it’s not green then it’s not active.
    To make it active click on it and “Restart All Services”

    restart-wamp
  4. Open any browser and type localhost or 127.0.0.1 on the address bar and you will see your WAMP server dashboard page.

    wamp-dashboard
  5. Download Magento CE:
    You can download magento community edition from this link. You can select your format of choice and download.

    download magento

    Installing Magento:-

    Now that you have the server all set, you can start the process of installing Magento.
    Extract the downloaded Magento file. Inside the extracted file you will see a folder named “magento”. You have to copy this folder in the root directory of your WAMP server. To get to the root directory, click on green WAMP icon and click “www directory”, your server root directory will open up.

    www root folder
    Copy the “magento” folder in this directory.
    Ok, so now you have the magento files ready for installation. But before you start installation, you have to create database for your site.
    Create Database:
    In your WAMP server Dashboard click on phpMyadmin link in Tools section.

    create-database phpmyadmin
    This will open the phpMyAdmin Page.
    Click on the database tab and type in the database name (suppose we name it magento1) and create the new database.

    phpmyadmin-database creation
    Your database creation is complete.

    Server configuration:

    For error-free installation you have to change some settings of your WAMP server.
    • Enable curl extension
      1. Click on your green WAMP icon -> PHP -> PHP extensions -> php_curl (at the top of the list) and click on it to make it active. Click on WAMP icon and Restart all services.

    • php_curl

      rewrite-module
    • Enable Apache rewrite module
      1. Click on WAMP icon -> Apache -> Apache Modules -> rewrite_module(towards the bottom of the list). Click on WAMP icon and Restart all services.
    • Modify php.ini file
      1. Click on WAMP icon -> PHP -> php.ini

      php-ini-file
      1. This will open up your php.ini file in a text editor. Search for “ max_execution_time “ in the file and you will find something like max_execution_time = 30 , change 30 to some arbitrary large value such as 1500. This change means we are changing the Maximum execution time of our server from 30 seconds to 1500 seconds.
      2. Similarly search for “ max_input_time ” and you will find “max_input_time = 60 ”, change 60 to 1500. Save the php.ini file.
    Now you are all set to install magento.
      1. Click on WAMP icon and Restart all services.Wait till the icon turs green.
      2. Open your WAMP dashboard and click on magento folder in Your Project section.

    magento-projects
      1. The Magento installation wizard opens up. Accept the terms and conditions and click on continue.

    Install-wizard
      1. The Localization settings page appears. No need to change anything here, you can change settings from backend later.
        Click on continue.
      2. Next the Configuration settings page appears. You have to give the Host name which will be “localhost” in this case. The Database name would be the one that we created earlier.
      3. User Name should be the Database user name. If you haven’t changed anything then it should be “root” and the password section would be blank.

    database-connection
    1. Keep others as it is and click on continue. This step will take some time as Magento will be creating the Database Tables.
    2. After this the Admin Account creation page appears. Fill in the details and remember the Username and Password, it will be required to access the Admin section. You can leave the Encryption Key section Blank. Click on continue.
    3. That’s it. You are done and have set up your first Magento Webstore.
    If you face any other issue while trying to install Magento on WAMP, please feel free to post it in the comment and I will be more than happy to help you.
    If you want any other Magento related post you can request that too. I will try my best to write a post on your requests.