Host file location in Windows

These are the host file location in various Windows versions

If Windows operating system is installed in C drive these are the locations

These are the host file location in various Windows versions

If Windows operating system is installed in C drive these are the locations

Windows 95 - C:windows
Windows 98 - C:\windows
Windows Me - C:\windows
Windows 2000 - C:windows\system32\drivers\etc
Windows XP - C:\windows\system32\drivers\etc
Windows NT - C:\winnt\system32\drivers\etc
Windows Vista - C:\windows\system32\drivers\etc
Windows 7 - C:\windows\system32\drivers\etc

If you don’t know in which drive Windows is installed, try these generic paths

Windows 95 - %WinDir%
Windows 98 - %WinDir%
Windows Me - %WinDir%
Windows 2000 - %SystemRoot%\system32\drivers\etc
Windows XP - %SystemRoot%\system32\drivers\etc
Windows NT - %SystemRoot%\system32\drivers\etc
Windows Vista - %SystemRoot%\system32\drivers\etc
Windows 7 - %SystemRoot%\system32\drivers\etc

If you are unable to edit host file in Windows Vista or Windows 7 check this Microsoft knowledge base: http://support.microsoft.com/kb/923947

Posted in Windows | Tagged | Leave a comment

Background image for website

Are you looking for good background texture images for your website.

Try these sites

SubtlePatterns

Subtle Patterns has lot of background texture image to choose from.
You can also submit your own textures from the Submit pattern page.

Demilked

Demilked has lot of paper background patterns.

Posted in Web development | Tagged , | Leave a comment

iOS 6.0 caching Ajax POST requests

Problem : Ajax requests are triggered from browser but not hitting the server. The requests are cached.

Device/OS : iOS 6.0 Safari

Platform (confirmed but not limited to) : Mobile web , Phone gap

Reason: By design iOS 6.0 is caching Ajax requests. This mostly happens when POST data is same as that of previous Ajax request. In iOS 6.0 POST requests are cached in the absence of no-cache headers.

This is considered as a bug because in other mobile/desktop browsers and iOS previous versions the POST requests are not cached even if no-cache headers are not set. Also this issue in iOS 6.0 causes existing web apps to break.

The issue has been fixed in iOS 6.1 beta release.

How to fix it: There are various methods to prevent caching of requests. The recommended method is adding a no-cache header.

This is how it is done.

jQuery:

Check for iOS 6.0 and set Ajax header like this.

$.ajaxSetup({ cache: false });

ZeptoJS :

Check for iOS 6.0 and set Ajax header like this.

$.ajax({
type: 'POST',
headers : { "cache-control": "no-cache" },
url : ,
data:,
dataType : 'json',
success : function(responseText) {…}

Server side

Java :

httpResponse.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");

Make sure to add this at the top the page before any data is sent to the client.

.NET

Response.Cache.SetNoStore();

Or

Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);

PHP

header('Cache-Control: no-cache, no-store, must-revalidate'); // HTTP 1.1.
header('Pragma: no-cache'); // HTTP 1.0.
Posted in Mobile Web, Web development | Tagged , , , , | Leave a comment

How to find X and Y position in a CSS sprite image?

You have a CSS sprite with lot of icons in it. How will you find the X and Y position of an icon in it to use in the CSS background-position property? Use can use Photoshop or Firebug to find X and Y via trial and error method. But there is a better way to find it.

Goto site www.getspritexy.com Open it in any latest browser. except Internet Explorer (IE is not supported now). Upload your sprite, use mouse to select an icon. Properties like background-position, width, height will be automatically generated, copy and use it your CSS class.

Update
Internet Explorer support is also added now.

Posted in CSS, Technology, Web development | Tagged , , | Leave a comment

trim function not working in Internet Explorer (IE)

In Internet Explorer trim function is not build into the String object, so if you try to call trim function like someString.trim() IE will throw an error like “Object doesn’t support this property or method”, which means IE could not find the trim function in the String object.

Here is the fix for that.

// Adding trim function to String object
if(typeof String.prototype.trim !== 'function') {
  String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g, '');
  }
}

This code first checks if trim function is available in the String Object, because trim function is available in Firefox and Chrome browsers.

Use the above code before you call the first trim function.

An example will look like

var myString = "                  some text                  ";

alert(myString.trim());

More details on trim function and benchmarking different trim functions can be found here

Posted in JavaScript | Tagged , , , | Leave a comment