PDA

View Full Version : Website survey form



theremotedr
07-09-2015, 10:29 AM
I have a website survey form which is here http://www.theremotedoctor.co.uk/survey_form.html

Its goal is to pop up when the customer leaves my site.
I have this code.

<script type="text/javascript">

window.onunload = unloadPage;

function unloadPage()

{

alert("YOUR MESSAGE HERE");

}

</script>

But i am not sure where i need to put it.
Please can you help.

Thanks

Beverleyh
07-09-2015, 12:20 PM
Best practise now is to put scripts before the closing </body> tag.

theremotedr
07-09-2015, 01:04 PM
Hi,

Ive now added it but i dont see it working when i leave the site.
Did i do something wrong,please take a look.

http://www.theremotedoctor.co.uk/

Beverleyh
07-09-2015, 03:06 PM
I don't see it in the source. Have you put it in an external file?

theremotedr
07-09-2015, 05:06 PM
Its at the bottom,see example below.


<script type="text/javascript">
document.getElementById("si" + "mple" + "_spc").value = "51892726990368-51892726990368";
</script>
</form>
<script type="text/javascript">

window.onunload = unloadPage;

function unloadPage()

{

alert("YOUR MESSAGE HERE");

}
</script>
</body>
</html>

Beverleyh
07-09-2015, 05:13 PM
I am looking in the http://www.theremotedoctor.co.uk/ page you posted - at the source code. The code isn't there.

theremotedr
07-09-2015, 05:23 PM
Sorry my mistake.

Here is the form http://www.theremotedoctor.co.uk/survey_form.html

Beverleyh
07-09-2015, 06:11 PM
I'm a little confused by what you're trying to do.

I'm guessing you're thanking them for completing the survey once they leave the page?

In that case, the message alert is working - just change the alert to your thank you message.

theremotedr
07-09-2015, 06:27 PM
No,
When they leave any page on my site then the script would operate and the survey form would be shown.
I have added the script here http://www.theremotedoctor.co.uk/accaudi.html?scrollto=selection as this is where it should be but still nothing.

The script needs to be on every page of mine so when leaving the survey is then shown.

Beverleyh
07-09-2015, 06:56 PM
So it's a redirect script you're after? You need more than an alert then. Try Googling for something like "confirm and redirect on page exit". I'm not sure how successful you'll be with a default JS confirm window though. I would have thought that on confirming page exit, you're cutting the connection with the browser so further functions/events (the redirect) wouldn't fire. I imagine you'd need to look for a custom/pseudo confirm popup? You might be able to find something by way of a jQuery plugin but I'm not sure.

From a user experience perspective, I would recommend that you don't try to hijack the user's browser. Typically, when people want to leave a site, they want to do just that and not be hindered by obtrusive popups unless they provide a useful function, such as clearing cookies or reminding that unsubmitted form data may be lost. It will likely annoy people and leave negative feelings (and could deter them from visiting the site again).