Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

153
Vistas
How to change body background-color for only IOS devices using javascript?

Trying to detect IOS device and set a different background color. But my code is not working. How can I do this simply with pure javascript ...?

JAVASCRIPT

var isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
if (isIOS){
  document.body.style.background = "rgba(0,0,0,1)";
  console.log('This is an IOS device');
} else{
  console.log('This is Not an IOS device');
}
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Only iphone detection is working but ipad detection not working. But in my case to change the background the setInterval function worked.

var isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
if (isIOS && window.matchMedia("(max-width: 615px)").matches) {
  console.log("This is an IOS device");
  setInterval(function () {
    document.body.style.background = "rgba(0,0,0,1)";
  }, 5);
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

Works for me. I’ve used backgroundColor to make it more specific

var isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
if (isIOS) {
  document.body.style.backgroundColor = "rgba(0,0,0,1)";
  console.log('This is an iOS device');
} else {
  console.log('This is Not an iOS device');
}

You could set a class instead, and in the class specify

.my-class { background-color: rgba(0,0,0,1) ! important; }

! important should make it override other styles.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda