Simple Living, High Thinking Nadim

October 8, 2008

Setting the FavIcon (webpage icon)

Filed under: Graphics and Design — Tags: — simplenadim @ 8:33 am

Sometimes little things become important to think of. One such thing is FavIcon or ‘Favorites Icon’ which is also known as webpage icon, shortcut icon, URL icon, bookmark icon etc. One example of this icon is shown below.

FavIcon Example

FavIcon Example

To add such icon the following line should be placed inside the <head> tag of the HTML document.

<link href=“dw.ico” rel=“shortcut icon” />

Where ‘dw.ico’ is the desired icon file name.

October 7, 2008

Dynamic Layout by JavaScript

Filed under: Layout Design — Tags: , , , — simplenadim @ 7:31 am

We usually design web page layout by DIV+CSS. In some cases we need more flexibility in layout design which can further be achieved by JavaScript. The following is an example of layout by JS in which there is a page header, a left navigation bar and a main body DIV. The size of the ‘main’ DIV is dynamic that gets updated each time the window is resized.

<html>
	<head>
		<style type="text/css">
			body {
				background: #000000;
				margin: 0;
			}

			#header {
				height: 60px;
				background: #880000;
			}

			#sidebar {
				background: #000088;
				width: 200px;
				height: 350px;
			}

			#main {
				position: absolute;
				left: 200px;
				top: 60px;
				background: #909090;
			}
		</style>

		<script type="text/javascript">
			function adjust() {
				var mainW, mainH;

				if (parseInt(navigator.appVersion)>3) {
					if (navigator.appName == "Netscape" || navigator.appName == "Opera") {
						// for FF, Opera use window.innerWidth and window.innerHeight
                                                mainW = window.innerWidth - 210;
						mainH = window.innerHeight - 90;
					} else if (navigator.appName.indexOf("Microsoft") != -1) {
                                                // for IE use document.body.offsetWidth and document.body.offsetHeight
               					mainW = document.body.offsetWidth - 230;
						mainH = document.body.offsetHeight - 110;
					}
				}

				var main = document.getElementById('main');
				main.style.width = mainW + 'px';
				main.style.height = mainH + 'px';
			}
		</script>
	</head>
	<body onload='adjust()' onresize='adjust()'>
		<div id='header'></div>
		<div id='sidebar'></div>
		<div id='main'></div>
	</body>
</html>

October 6, 2008

IE Cache Control Prevents AJAX from Sending Requests to Same URL

Filed under: AJAX Problems and Solutions — Tags: , — simplenadim @ 2:26 pm

Once I was stuck in a very bothering problem, I was sending an AJAX request to the same URL (a PHP script) on and on. It worked fine in FF and Opera, the things were getting updated as I expected. But IE showed some bothering behavior. Since I was sending request to the same URL, IE was not allowing AJAX to send request to the actual URL rather it was retrieving the responses from its cache. So the things were not getting updated as I was expecting. I googled and found out solution to this problem. I found the following solution from googling.

You need to force no caching by adding the following lines just before you call xhr.send(null), where xhr is the XMLHTTPRequest.

xhr.setRequestHeader(“If-Modified-Since”, “Thu, 1 Jan 1970 00:00:00 GMT”);

xhr.setRequestHeader(“Cache-Control”, “no-cache”);

I also devised another way. Since the problem is due to the same URL, we can change the URL by adding some random number which makes the URL look different each time it is used and it doen’t affect the URL. The following is another solution.

xhr.open(“GET”, “http://my-address/myscript?myparam=dummy&rand=” + Math.random(), true);

Blog at WordPress.com.