October 12, 2010
OK, you probably don’t need to do this but I bet you’ve seen it done – you go to a website and suddenly – either immediately or a few seconds later – it redirects you to another site. It can be useful and legitimate or just plain deceitful and annoying. It all depends on the intention.
Well if your intentions are good then I’ll tell you how it’s done. (Or at least show you one way to do it – there’s always more than one way.)
Here’s some sample code:
(Like all HTML, wrap some brackets < > around it to make it work and pop it into the HEAD of your HTML page, ie after the HTML tag but before the BODY tag.)
meta http-equiv=”REFRESH” content=”0;url=http://www.the-domain-you-want-to-redirect-to.com”
(Don’t forget to close off your “meta” tag, either.)
So what happens here?
Well the meta content=”0;url=http://<b>the-domain-you-want-to-redirect-to</b>.com” http-equiv=”REFRESH” is the part that actually does the redirecting or “refreshing”. The number before the URL (in this case “0″) tells your web browser the number of seconds to wait before redirecting to the new address (or URL). You could set this to 3 or 5 and add some explanatory text or just leave it at zero. Whatever suits your purposes.
So what do I do with this?
Just copy the code above into your HTML editor of choice – it could be Kompozer or even just Notepad – and save it as something that makes sense. It could be index.html if it’s redirecting traffic off your domain or subdirectory root, which is the most likely use. Don’t forget to change the domain name to the one you want to redirect to – and remember you can be explicit, right down to the page you want your visitor to land on.
For example I just put it to use in refreshing a page which contained an inline frame. I had a list of .PDF files inside the frame and if clicked they opened (that’s the intention) – but you had to get out and back in again to get back to the list.
Instead of making visitors load a new page and then return I added a “Click here to refresh this list” button that simply took the browser out of that page to “refresh.html”, a page that carries a “List refreshing now…” message and the above code. All it does is redirect back to the page with the inline frame – and voila! – the list has refreshed. Job done. And that’s a legitimate use.