This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

Themabewertung:
  • 0 Bewertung(en) - 0 im Durchschnitt
  • 1
  • 2
  • 3
  • 4
  • 5
if Abfrage mit Funktion abhängig vom Datum
#1
Hallo Javascript-Experten,

ich habe ein Problem mit einem kleinen Skript... das in iOS (also iPhone, iPad, iMacs) nicht das macht was es soll.
Die Idee ist, dass abhängig vom Datum eine function definiert wird, die das Öffnen eines versteckten Inhaltes ermöglicht.

Das Javascript:

<script type="text/javascript">
  var dx = new Date();
  var d1 = new Date("2021-12-24");

  var openme = (dx-d1);
  if (openme > 0) {
     function openElement() {
         document.getElementById('divId').style.display = 'block';
     }
}

</script>

Die Funktion openElement() wird in einem Link per onclick = "openElement()" aufgerufen.

In Google Chrome und Firefox funktioniert das einwandfrei, da die Funktion openElement() vor dem 24. Dezember nicht definiert ist.
Bei allen Geräten mit iOS, also auf iPhones, iPads bzw. im Safari-Browser auf meinem iMac funktioniert die Abfrage if (openme > 0) nicht so wie sie soll... d.h. die Funktion openElement() ist unabhängig vom Ergebnis der if-Abfrage immer definiert und somit wird der Inhalt immer angezeigt.

Hat jemand eine Idee woran das liegt?
Was muss ich im obigen Script ändern, damit es auch für iPhone, iPads und in Safari funktioniert?

Merci schon Mal für eure Tipps und viele Grüße!
Zitieren


Gehe zu:


Benutzer, die gerade dieses Thema anschauen: 1 Gast/Gäste