Archive for the ‘Javascript’ Category displays the cached version of page

January 29, 2009 JavaScript function inherently opens the cached version of the page requested. For the first time the web page will be brought from the server, but for subsequent requests it will display the cached version of the page that was bought first. How to avoid this..? shows the cached version of the page ONLY if the URL requested matches the cached page URL. The best option is to change the URL every time you try to use the statement. This can be achieved by two methods:

  1. Append a dummy queryString with Random value
  2. Append a dummy queryString with DateTime stamp

Out of the two the second method is most reliable, since the DateTime stamp will be unique every time you invoke the statement. Example:

var dt = new Date().toString();
var URLToOpen = '' + dt;'New Page','',URLToOpen);

Your comments are welcome.


How to get the position of a control using Javascript?

January 24, 2009

Here is a handy functions to get the posisiton of a control using Javascript:


alert(getElementPosition('txtName').top + ' ' + getElementPosition('txtName').left);


 function getElementPosition(elemID) {
var offsetTrail = document.getElementById(elemID);
var offsetLeft = 0;
var offsetTop = 0;
while (offsetTrail) {
offsetLeft += offsetTrail.offsetLeft;
offsetTop += offsetTrail.offsetTop;
offsetTrail = offsetTrail.offsetParent;
return { left: offsetLeft, top: offsetTop };

We can get the current scroll position of the document using:

var scrolly = typeof window.pageYOffset != 'undefined' ? window.pageYOffset : document.documentElement.scrollTop;
var scrollx = typeof window.pageXOffset != 'undefined' ? window.pageXOffset : document.documentElement.scrollLeft;

Hope this helps you…

Javascript to Bookmark a website!

January 2, 2009

Here is a javascript function to bookmark any website:
javascript:bookmark(‘’, ‘Sandeep Aparajit Blogs’);

<script type="text/javascript">
function bookmark(url,title)
if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4))
else if (navigator.appName == "Netscape")
alert("Press CTRL-D (Netscape) or CTRL-T (Opera) to bookmark");

Hope this helps 🙂