Hilfe durchsuchen

Vorsicht vor Support-Betrug: Wir fordern Sie niemals auf, eine Telefonnummer anzurufen, eine SMS an eine Telefonnummer zu senden oder persönliche Daten preiszugeben. Bitte melden Sie verdächtige Aktivitäten über die Funktion „Missbrauch melden“.

Weitere Informationen

How do I get naturalWidth / naturalHeight?

  • 1 Antwort
  • 1 hat dieses Problem
  • 1 Aufruf
  • Letzte Antwort von vrcode

more options

I believe there is a bug. I can't get naturalWidth / naturalHeight in Firefox. Neither Safari nor Chrome has this problem.

JavaScript code:

let image = document.querySelector("img"); console.log("natural width=" + image.naturalWidth + ", " + "natural height=" + image.height);

The code printed a value of 0 in Firefox whereas browsers printed the respective width and height of the image.

I believe there is a bug. I can't get naturalWidth / naturalHeight in Firefox. Neither Safari nor Chrome has this problem. JavaScript code: let image = document.querySelector("img"); console.log("natural width=" + image.naturalWidth + ", " + "natural height=" + image.height); The code printed a value of 0 in Firefox whereas browsers printed the respective width and height of the image.
Angefügte Screenshots

Ausgewählte Lösung

Edit:

solution/workaround: wait for everything to completely load by putting code in


       window.addEventListener('load', function() {
       //code
       });
Diese Antwort im Kontext lesen 👍 0

Alle Antworten (1)

more options

Ausgewählte Lösung

Edit:

solution/workaround: wait for everything to completely load by putting code in


       window.addEventListener('load', function() {
       //code
       });

Geändert am von vrcode