A
A
artekha2016-09-07 22:22:40
css
artekha, 2016-09-07 22:22:40

The script does not work in safari, how to fix it?

This site www.webraketa.com/2301-2 has two buttons and a timer. Buttons with the inscription: Buy record for 7$ 49$ .
When the timer ends (47 minutes), the buttons should change color from green to orange, and the inscription in the button itself should also change to: Buy record for $7.
It works in chrome, in safari technology preview too, but it doesn’t work in regular safari, I don’t know how to find out why.
If anything - here is the code for replacing the text and color of the buttons (the replacement time is set to 1 minute):

// Javascript starts 2820
  countdown4 = 60;

  function getCookie(c_name) {
    var i, x, y, ARRcookies = document.cookie.split(";");
    for (i = 0; i < ARRcookies.length; i++) {
      x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
      y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
      x = x.replace(/^\s+|\s+$/g, "");
      if (x == c_name) {
        return unescape(y);
      }
    }
  }

  function setCookie(c_name, value, exdays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + exdays);
    var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString());
    document.cookie = c_name + "=" + c_value;
  }

  // Converting date difference from seconds to actual time

  function convert_to_time(secs) {
    secs = parseInt(secs);
    hh = secs / 3600;
    hh = parseInt(hh);
    mmt = secs - (hh * 3600);
    mm = mmt / 60;
    mm = parseInt(mm);
    ss = mmt - (mm * 60);

    if (hh > 23) {
      dd = hh / 24;
      dd = parseInt(dd);
      hh = hh - (dd * 24);
    } else {
      dd = 0;
    }

    if (ss < 10) {
      ss = "0" + ss;
    }
    if (mm < 10) {
      mm = "0" + mm;
    }
    if (hh < 10) {
      hh = "0" + hh;
    }
    if (dd == 0) {
      return (hh + ":" + mm + ":" + ss);
    }
    else {
      if (dd > 1) {
        return (dd + " day " + hh + ":" + mm + ":" + ss);
      }
      else {
        return (dd + " day " + hh + ":" + mm + ":" + ss);
      }
    }
  }
  if(getCookie('countdown')){
    countdown4 = getCookie('countdown');
  };

  // Our function that will do the actual countdown
  do_cd4 = function() {
    if (countdown4 < 1) {
      // change text
      console.log('yes');
      var buttons = document.querySelectorAll('.counter-button');
      buttons.forEach( function(element, buttons) {
        element.classList.add('discount-ended');
        element.href = 'http://webraketa.ecommtools.com/buy/36' 
        element.innerHTML = 'Купить полную запись за 49$';
      });
      setTimeout('do_cd4()', 1000);
    }
    else {
      console.log(countdown4);
      setTimeout('do_cd4()', 1000);
    }
    setCookie('countdown', countdown4, 3);
    countdown4--;
  }
  do_cd4();

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question