Tuesday, April 23, 2013

Rotating Banner for your website with HTML and JavaScript

What is Rotating Banner?

Web banners play an immense part in today's advertising methods. While browsing in the web, you can see advertising banners that is cycling through a number of images each of them linking to specific target pages. Let us see the code to create such a rotating web banner to be used in your website and bit of understanding about the code.

I am using Dreamweaver as my HTML editor software. You can use any available editors of your choice.
  • Create a new HTML file and my editor automatically provides the very basic tags embedded within the file.
  • Create a top section on your web page for the banner to be displayed using <div> tag 
<div>
  <a href="_blank"><img src ="images/Chrysanthemum.jpg" height="200" width="1345"  id="banner"/>
   </a>
</div>

My first image on the rotating banner is "Chrysanthemum.jpg" placed in images folder with id attribute for <img> tag as "banner".
  •  Now enter into the JavaScript code within the script tags.
<script language="javascript" type="text/javascript">
</script>
  • We write a rotate() function to flip through the images with a tiny time gap. Create a variable "ad" and initialise it to "0" outside the function.
function rotate()
 {
     var images = new Array ("images/Chrysanthemum.jpg", "images/Desert.jpg", "images/Hydrangeas.jpg");
     ad++;
     if (ad == images.length)
      {
        ad = 0; 
      }
     document.getElementById("banner").src = images [ad] ;
     setTimeout(rotate, 2000);
 }


Within the function a new array called images is created with the image files. The setTimeout function is used to call the rotate() function every 2000 milliseconds. Each time the function is called the "ad" value will be incremented and the "src" attribute of the banner element will be substituted with image from the images array with index as the current "ad" value.
  • We need to add links to each image with a function named newlocation().
function newlocation ()
 {
     var url = new Array ("http://www.google.com","http://www.yahoo.com","http://www.bing.com");
     document.location.href = url [ad];
     return false;
 }


Within this function a new array called url is created with the links to each image. The entire URL of the document is substituted with link from the url array with index as the current ad value.
  • Its time to call the functions now as below.
 document.getElementById("banner").parentNode.onclick = newlocation;
 rotate();


Whenever an image is clicked the newlocation() function is called with the help of onclick event and rotate() function is called directly. This is the basic code for rotating banner and you can add any style to your banner with the help of CSS.

Download code here

Thursday, April 4, 2013

Tips for hassle free use of iPhone by boosting the battery life

  • Turn off Fetch New Data for Mail
Go to Settings -> Mail ->Fetch New Data and turn off Push. Select the option "Manually" from the Fetch options given below. Open the Mail app to receive the emails whenever you wish to read.
  • Auto-Lock feature
Go to Settings -> General ->Auto-Lock. Set the Auto-Lock to 1 Minute to save the battery life.
  • Turn off Bluetooth and Wi-Fi
When you are not using any Bluetooth devices with your iPhone, turn off Bluetooth. Go to Settings -> Bluetooth and turn off. Similarly turn off Wi-Fi when you don't use it. Go to Settings -> Wi-Fi to turn off.
  • Turn on Auto-Brightness
Go to Setting -> Brightness and turn on Auto Brightness. The sensor will detect if you are in bright or dark lighting condition and adjust the brightness of your iPhone as per the condition. This will protect your eyes as well as save battery power.
  • Adjust Equalizer
Go to Settings -> Music ->EQ. Set EQ to "Flat" to conserve battery power.
  • Update to the latest version of the iPhone software. 
  • Turn off Location Services
Go to Settings ->Privacy ->Location Services. Turn off the location services and whenever you open a app that requires location services, it will ask you to turn on the Location services in settings. You can either turn on the feature at that moment or use the app without enabling the service.
  • Keep the iPhone always in room temperature. Avoid leaving the phone either in too hot/cold conditions.
  • Turn off Notifications 
Go to Settings ->Notifications and turn off notifications for those apps from which you don't want to receive any notifications.
  • Once a month, drain your battery completely and then recharge to save battery lifetime. 

Note: All the above stated tips or some of them can be used, based on the preferences in the elements of the iPhone that are intensely being used by the particular person.