Archive for the ‘HTML and Javascript Tips’ Category

How to Reload a Page Only Once Using Javascript

Monday, July 7th, 2008

Here is a small piece of code that allows to reload a page only once. This is necessary to prevent some data being cached and this is the only solution I found good for my needs. Meta tag nocache did not save me, and meta tag refresh does not allow to refresh the page only once. So here is the code:

<script>
var reloaded = false;
var loc=”"+document.location;
loc = loc.indexOf(”?reloaded=”)!=-1?loc.substring(loc.indexOf(”?reloaded=”)+10,loc.length):”";
loc = loc.indexOf(”&”)!=-1?loc.substring(0,loc.indexOf(”&”)):loc;
reloaded = loc!=”"?(loc==”true”):reloaded;

function reloadOnceOnly() {
if (!reloaded)
window.location.replace(window.location+”?reloaded=true”);
}
reloadOnceOnly();
</script>

I found this in Google, but I had to spend some hours before I did it. So I think this article will be helpful for you.

Showing an Image on Remote Server Error

Tuesday, May 6th, 2008

If you’re hotlinking images from other servers (this is often used when adding banner codes), you might face the situation when remote server becomes unavailable. This will spoil your site look, if you don’t add a simple code, that allows to solve this issue.
<img src="BANNER URL(REMOTE)" onError="this.src='LOCAL URL SHOWN ON REMOTE SERVER ERROR'" height=31 width=88>

This simple code will save you from worrying on remote server uptime. That’s also a nice solution for showing remote server uptime - if you cannot get an image from remote server, the server shoulf be experiencing problems. You this and you’ll forget about banners with X signs.