Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

152
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!