Wednesday, September 21, 2005

Preventing a participant (or user) from accidentally leaving a page or closing a window prematurely

When using DHTML for behavioral experiments, one thing you certainly wish not to be possible, is that before the experiment is finished and the data were saved or submitted, your subjects can accidentally close the window (by clicking on the window close button, or pressing Ctrl-W, or even pressing Alt-F4), or unload the page in any other way (e.g., pressing the reload button or pressing F5). To prevent such accidents you can use an onbeforesubmit event handler. (Fortunately it is not possible to prevent such actions that are carried out deliberately.) The simplest is to copy and paste the code below and put it in your HTML page:
<script>
window.onbeforeunload = confirmExit;
function confirmExit()
{
   // you might consider conditionalizing 
   // this return statement
   return "You haven't finished yet!" +
          " Please press 'Cancel' to continue.";
}
</script>
This works in MSIE 5.1 and higher, and in Firefox 0.9 and higher.

Monday, September 19, 2005

Opening your HTML page in full screen mode

How to start your DHTML page in 'theatermode' (or 'channelmode' or 'full screen' mode, whatever...)

If you are using DHTML for psychological experiments, you would often like to get rid of the window border and have the entire display covered by a background. This was possible in MS Internet Explorer if you would open a popup window with one of the parameters set to channelmode (see the example here, which will open such a window if you click the button), or by resizing and repositioning the window such that the window borders would fall of the screen. For security reasons (phishing, and the like) this has changed in recent updates of MSIE. Now, you cannot get rid of the window if the document is loaded over an http connection. It is still possible to have the screen entirely occupied by you HTML-page if you load it from the hard disk (e.g., when you use MSIE as a substitute for behavioral research software and don't want to spend ridiculous amounts of public funding money on products such as E-prime). The secret is in the launch flags of MSIE that hardly anyone knows about: If you click Start &rightarrow; Run and type “iexplore.exe -k” followed by the full address of your file (i.e., 'iexplore.exe -k “c:\Documents and settings\John Doe\Desktop\myExperiment.html”') , then MSIE will launch in theater mode with the indicated file opened. You can close the window with Alt-F4.

This is probably not the most convenient way to start your experiment each time with a new participant is tested. Instead, you can place a shortcut on the desktop: First right click the HTML file that implements your experiment, choose 'Send to desktop (creates shortcut)'. Then, on the desktop right click the freshly created shortcut and choose 'Properties'. A tabbed window opens, choose the tab 'Shortcut'. In the target field, you'll find the name and path of you HTML file. Put the cursor in front of and type the full path and name of the internet explorer executable in quotes (something like '"C:\Program Files\Internet Explorer\iexplore.exe"', followed by '-k' and a whitespace (see the image below). Click 'OK'; you're done. You'll notice that the icon of your shortcut has changed spontaneously to the icon you'd expect for a shortcut to MSIE itself. If you double click the shortcut your experiment starts automatically in full screen mode.

Friday, August 12, 2005

Changing the appearance—or getting rid—of the mouse pointer

When using DHTML to do psychological experiments, you're likely to want to get rid of the mouse pointer as stimuli are presented. This is very easy fortunately. In principle you can have your mouse pointer look like anything that you can make a picture look like: First you create a bitmap (e.g., a blank one), and then you turn it into a .ico file. Then, on the body element (or any other element) of the HTML page you specify a cascading style sheet that includes the specification "cursor: url('mymouse.ico');" (of course 'mymouse' may be anything you like).

example: the George W. Bush fan DIV

<div style="cursor: url('gwbush.ico')">
Move your mouse over this text, you Georgey fan!
</div>

Here's the ico image that is used. You can make any bitmap in paint, for example, but that program won't save it as an .ico file. You can however copy and paste your design to IrfanView, from which you can save it as an .ico file.