Thursday

IE 7 meta refresh bug

This is seriously crazy - the old-school

<meta equiv="Refresh" content="3;url=http://mytest.local">

does not work in IE 7 with default settings because of security settings disabling the meta-refresh.


Solution:

In the HEAD section:


function Refresher(t) {
if(t) refresh = setTimeout("document.location='http://www.mysite.com';", t*1000);
}



And I call the script inside the BODY tag:

<body onload="Refresher(20)">

Where the parameter is the amount of seconds that IE should wait until refresh.

Tip o' the hat to http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=870204&SiteID=1

1 comment:

Mark Fennell said...

This is actually a very useful alternative to the meta-refresh since you can abort/cancel the refresh if the user causes an event on a page. For example, I have a web app that refreshes a page so that the helpdesk can view current and new calls without having to refresh. However, if they've clicked in the search box or something, the meta tag doesn't care. However, with this handy tip, I can cancel the timeout. Thank you! This is very helpful for me.