Per una apertura random, occorre anche conoscere (nello script) le dimensioni della finestra, per cui le features vanno "montate" nella funzione:
Chiamata:
<body onUnload="openWinRand('../popups/popupregina. htm', '',320, 240, 'scrollbars=no');">
Funzione
codice:
function openWinRand(theURL,winName,w,h,ofeatures) {
var lar = screen.availWidth;
if(lar==0) lar = screen.width;
var hei = screen.availHeight;
if(hei==0) hei = screen.height;
var x = Math.floor(Math.random()*(lar-w));
var y = Math.floor(Math.random()*(hei-h));
var features = "left="+x + ",top="+y;
features += ",width="+w + ",height="+h + ","+ofeatures);
window.open(theURL,winName,features);
}