Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

Q1195 How can I ask one in ten visitors if they want to carry out a survey?

irt.org | Knowledge Base | JavaScript | Random | Q1195 [ previous next ]

Q1195 How can I ask one in ten visitors if they want to carry out a survey?

It might be simpler to just do:

<script language="JavaScript"><!--
var nth = 10;
var rnd = Math.floor(Math.random() * nth) + 1;

if (rnd == nth) {
    if (confirm("Do survey?")) {
        location.href = 'survey.htm';
    }
}
//--></script>

If you must have a popup window then use:

<script language="JavaScript"><!--
var nth = 10;
var rnd = Math.floor(Math.random() * nth) + 1;

if (rnd == nth) {
     var windowHandle = window.open('popup.htm','windowName','width=400,height=400');
     if (!windowHandle.opener)
         windowHandle.opener = self;
}
//--></script>

then in popup.htm:

<script language="JavaScript"><!--
function yes() {
    opener.top.location.href = 'survey.htm';
    opener.focus();
    setTimeout('window.close()',10000);
}
//--></script>

Do survey?
<form>
<input type="button" value="Yes" onClick="yes()">
<input type="button" value="No" onClick="window.close()">
</form>

Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 6th July 2009. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2009 irt.org, All Rights Reserved.