Greg's Blog

helping me remember what I figure out

Extending Sessions

| Comments

There are always moments when a user leaves his browser window open, goes off does something else, comes back and bang the information he was carefully entering has disappeared. A truly annoying sequence of events and due to the web’s stateless nature not too uncommon. Granted such a situation happens rarely, but sometimes users have to read quite lengthy documents in order to make a decision, and depending on your reading speed this could leave you facing a similar situation. SO here is the hack.

By making use of a 1 px high, by 1 px wide <iframe> that is embedded in the template that the user is looking at and which calls a page that is instructed to refresh at a set interval you can fake a user interacting with the application for days on end. Without further ado the code, first the template (aptly called iframe.cfm) with the <iframe>.

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”>

<html>
<head>
<title>Untitled</title>
</head>
<body>
<iframe src=”refresh.cfm” name=”get_time” height=”55” width=”170” scrolling=”No” frameborder=”0”></iframe>
<p>The content can appear here</p>

</body>
</html>

And now the template that refreshes every 60 seconds (refresh.cfm)

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”>

<html>
<head>
<title>Untitled</title>
<META HTTP-EQUIV=”REFRESH” CONTENT=”60;URL=???”>
</head>

<body>
<cfoutput>#now()#</cfoutput>
</body>
</html>

Now the real trick to this working is the <META> tag in the header section of the document, which refreshes, in this case every seconds (CONTENT=”60;URL=???”). If you were to increase the size of the <iframe> you’d be able to see that the time stamp generated and output in refresh.cfm changes every minute, thus proving that something happens every seconds, alternatively just leave your browser window open overnight on the application page you are testing this for and see what happens the next day.

One small caveat is that not all browsers, if memory serves me right support the <META HTTP-EQUIV=”REFRESH” CONTENT=”60;URL=???”> so be aware of this…