Creating a Custom "Survey Offline" WebProd Page
Summary | This article describes how to utilize JavaScript to create a customized "Survey Offline/Unavailable" screen in WebProd |
Applies to | AskiaWeb |
Written for | Scriptwriters and Survey Authors |
Keywords | webprod; offline; script |
Download example script here.
Utilizing a combination of JavaScript and HTML, it is possible to create a customized page that WebProd will redirect a respondent to in the case of a "103 Survey Offline" Error.
This is useful in the situation of invitation links having been sent to respondents, who may attempt to access them well after your survey has finished field.
Please Note: If your survey is offline, but still taking an active WebProd slot, the default "Offline" Final Page dictated in Askia Design WILL override this code.
Implementation
Placing this functionality into WebProd is relatively simple. Using the script provided, it can then be pasted into the "General Error Page" dialogue in the WebProd Configuration window:
The JavaScript template will be used like this:
<div>Error: ??WEBPROD_ERROR??.</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
var foundin = $("div:contains(\"(cause 103)\")").length > 0;
foundin = foundin || $("div:contains(\"Error 1003\")").length > 0;
var bodyText = $("div").text();
var quote = unescape("%27");
var taskName = bodyText.substring(bodyText.indexOf(quote)+1,bodyText.lastIndexOf(quote));
var redirectURL = "/AskiaEndPage/" + "EndPage.htm";
if (foundin) {
checkIfRemoteFileExists(redirectURL);
}
function checkIfRemoteFileExists(url) {
$.ajax({
url:""+url+"",
error: function()
{
// do nothing; file does not exist
},
success: function()
{
window.location.href = url;
}
});
}
});
</script>
The code's functionality relies on looking for the "Cause 103" Default Error text to appear. Depending on this, the script will utilize an AJAX call to redirect the respondent to a pre-determined HTML page located on the Survey's respective Web machine by replacing the URL.
In this case, the HTML file was located under:
C:\inetpub\wwwroot\AskiaEndPage\EndPage.htm
The code provided can also be altered by a survey programmer with a working knowledge of HTML/JavaScript to further customize the function to suit the client's needs.