-
damiancooperAnswered on June 02, 2016 09:27 AM
Hi can you help with my popup form. I have loaded it to a test page it all looks fine with a delay to open, but every refresh of the page it still loads the form. http://www.purestoves.co.uk/extras.html
-
CharlieAnswered on June 02, 2016 10:49 AM
It seems like you have placed the Lightbox box embed code incorrectly.
As mentioned in this guide https://www.jotform.com/help/140-Using-cookies-to-auto-open-a-lightbox-form-per-browser-session. You need to paste the script in between the second <?php ?> code.
Also, your webpage needs to run PHP scripts, pages ending in .php. Your website is only in .html. You also need to have a working web server for this.
Please do follow the steps mentioned in the guide and make sure that your page is able to run or load PHP scripts.
-
damiancooperAnswered on June 02, 2016 12:38 PM
Hi Charlie, is there a way of doing this in html? I can't make the page php.
-
CharlieAnswered on June 02, 2016 01:27 PM
Based from the guide, you'll need to use PHP to set, get and check the cookie. I'll try to look for a workaround using Javascript. I'll get back to you as soon as I find one. Thank you.
-
CharlieAnswered on June 02, 2016 02:00 PM
Hi,
I found a way using Javascript. I'm using the document.cookie function found here: http://www.w3schools.com/js/js_cookies.asp
Here's my test website page: https://shots.jotform.com/charlie/script_cookie_saver.html. It is an HTML page, however, you need to make sure that your website can run scripts.
You can get my script code here: https://github.com/LightDev777/JotForm-Scripts/blob/master/Cookie%20Checker
This is my original Lightbox embed code, make sure you set it to "Open On Page Load":
<script src="https://form.jotform.com/static/feedback2.js?3.3.REV" type="text/javascript">
var JFL_61534912534959 = new JotformFeedback({
formId: '61534912534959',
base: 'https://form.jotform.com/',
windowTitle: 'Clone of Pure Feed Back form',
background: '#FFA500',
fontColor: '#FFFFFF',
type: '1',
height: 500,
width: 700,
openOnLoad: true
});
</script>
Now my final script code would be like this:
<script src="https://form.jotform.com/static/feedback2.js?3.3.REV" type="text/javascript">
checkCookie();
function setCookie(cname, cvalue) {
document.cookie = cname+"="+cvalue+"; ";
}
function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
function checkCookie() {
var user = getCookie("username");
if (user == "visited") {
/*Do something here if the user is returning*/
alert("Welcome back!");
} else {
/*Place the JotForm Lightbox embed code here*/
var JFL_61534912534959 = new JotformFeedback({
formId: '61534912534959',
base: 'https://form.jotform.com/',
windowTitle: 'Clone of Pure Feed Back form',
background: '#FFA500',
fontColor: '#FFFFFF',
type: '1',
height: 500,
width: 700,
openOnLoad: true
});
setCookie("username", "visited");
}
}
</script>
The green highlight in my final code is the original code from the lightbox.
The yellow highlight in my final code is the custom script that you need to add.
The text set in bold are the actions taken. The first one allows you to set actions on what to do is the visitor is just returning on that session, meaning it's not the first time he/she visited the page on that time. The second part is the actual JotForm lightbox embed code, I'm basically displaying the form and at the same time setting up the cookie for that user because he's a first time visitor.
Let us know if that will work.
-
damiancooperAnswered on June 06, 2016 07:27 AM
Hi Charlie
I am also trying to incorporate a delay on load, which I did have working but before. Is there any way of having the 2 functions working together?
-
CharlieAnswered on June 06, 2016 09:25 AM
It should be possible by following this guide: https://www.jotform.com/help/203-How-to-Auto-popup-a-Lightbox-Form
The only change we need to apply on our Lightbox embed code is we will NOT enable the "Open on Page Load" option.
With that, you'll have an anchor link on your embed code, meaning the Lightbox form is displayed ONLY if the anchor link is clicked. Now what we will do is to create a script that will automatically click that link to open the Lightbox form based on a delay using the setTimeout function. Here's the guide about it that I mentioned earlier: https://www.jotform.com/help/203-How-to-Auto-popup-a-Lightbox-Form
Now combine it with the one that we currently have, the final output would look like this code:
https://github.com/LightDev777/JotForm-Scripts/blob/master/Lightbox-cookie-based-with-delay
You can check my sample website here: https://shots.jotform.com/charlie/lightbox_cookie_based_with_delay.html. It has a delay of 10 seconds before the Lightbox opens.
Let us know if you need further help on this.
-
damiancooperAnswered on June 07, 2016 07:09 AM
Done
Thanks for all your help.
-
CharlieAnswered on June 07, 2016 08:55 AM
You are most welcome. You should you need our assistance again, please do not hesitate to visit us here in the forum.
Thank you.