i am trying to do something that it's still out of my league. I have used before script on website to show Button after 1 minute from video time. So when Video player comes to 01:00 the button is shown and after that it saves that to cookie so the next time you visit page it's shown right away and you don't have to wait another 1 minute so button can be shown.
But now i am trying to connect this timer to the website time, not the video time, and i am pretty lost.
Function calling in Index page:
<script type="text/javascript">
var minuten = 0;
var sekunden = 5;
//==========================
cartt(minuten, sekunden);
</script>
This is the original code of the video time:
$("#video").fitVids();
var video = new Vimeo.Player($('#video iframe'));
function cart(minuten, sekunden) {
var button = $('.cart');
var seconds = (minuten * 60) + sekunden;
var url = window.location.pathname;
url = url.split("/");
var seite = url[url.length -1];
var cookie_string = "cartbutton_" + seite + "=show";
var cookieIsSet = function() { return document.cookie.indexOf(cookie_string) != -1; };
if(!cookieIsSet()) {
button.hide();
video.on('timeupdate', function(data) {
if (data.seconds >= seconds && !cookieIsSet()) {
button.show();
document.cookie = cookie_string + "; max-age=259200";
}
});
}
}
And this is how i am trying to get website time:
window.onload=function(){
var start=Date.now();
}
function cartt(minuten, sekunden) {
var button = $('.cartt');
var seconds = (minuten * 60) + sekunden;
document.write(seconds);
var url = window.location.pathname;
url = url.split("/");
var seite = url[url.length -1];
var cookie_string = "cartbutton_" + seite + "=show";
var cookieIsSet = function() {
return document.cookie.indexOf(cookie_string) != -1;
};
if(!cookieIsSet()) {
start.on(function(data) {
if (data.seconds >= seconds && !cookieIsSet()) {
button.show();
document.cookie = cookie_string + "; max-age=259200";
}
});
button.hide();
}
}
(Posted on behalf of the OP).
I have managed to make this by myself, since there are no answers and I couldn't find this answer on the web, I will share my solution.
On index page:
<script type="text/javascript">
var videoShow = getCookie('video-show');
jQuery(document).ready(function() {
if(videoShow) {
jQuery('.cartt').show();
}
else {
setTimeout(
function(){
jQuery('.cartt').show();
setCookie('video-show', 1, 365);
}, 5000 );
}
});
</script>
The script:
function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
var dpath = '/';
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toUTCString())+";path="+dpath;
}
function getCookie(c_name)
{
if (document.cookie.length>0)
{
c_start=document.cookie.indexOf(c_name + "=");
if (c_start!=-1)
{
c_start=c_start + c_name.length+1;
c_end=document.cookie.indexOf(";",c_start);
if (c_end==-1) c_end=document.cookie.length;
return unescape(document.cookie.substring(c_start,c_end));
}
}
return "";
}