Issues with Javascript media queries not responding as expected on Safari and iOS devices

Seeking assistance from anyone who can offer help.

The code below functions properly in all browsers except Safari.

 if(window.matchMedia('(resolution:320dpi)').matches){res = i;}
 if(window.matchMedia('screen and (resolution:320dpi)').matches){wkres = I;}

Has anyone found a solution to make Safari acknowledge and execute these queries? All help and advice is greatly appreciated.

Answer №1

Unfortunately, Safari does not currently support the resolution property, but there are indications that this issue has been resolved and will be included in a future Safari update.

However, Safari does support the window.devicePixelRatio, which provides information on the ratio of device pixels to CSS pixels (measured in 96ths of an inch).

To work around the lack of support for resolution, you can use a code snippet like this:

const is320dpiOrMore = (window.devicePixelRatio * 96) >= 320;

Answer №2

According to the information above, Safari does not support matchMedia resolution, but it does support the non-standard -webkit-device-pixel-ratio.

/* When using "-webkit-min-device-pixel-ratio: 2", a unit of "dppx" is implied: */
@media (-webkit-min-device-pixel-ratio: 2) { ... }
/* This code is equivalent to: */
@media (min-resolution: 2dppx) { ... }

/* Similarly for "-webkit-max-device-pixel-ratio: 2": */
@media (-webkit-max-device-pixel-ratio: 2) { ... }
/* This code is equivalent to: */
@media (max-resolution: 2dppx) { ... }

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

"New app built in Swift can be up and running in just under

My Swift application includes an array of approximately 100,000 strings in the following format: let strings: [String] = [ "a", "as", // 99,998 elements later... "zebra" ] Building and running the app in the iOS Simulator takes about 6 mi ...

Calculate the total sum of a specific property within an array using ES6

My goal is to calculate the total unit value by date and create a new array without duplicate dates. For instance, I want to sum up the values of 2015-12-04 00:01:00. This particular date appears twice in the dataset with values of 5 and 6, resulting in: ...

Detecting a single click versus a drag using RxJS

Currently, I am working with an AngularJS component that needs to respond to both single clicks and drags for resizing purposes. To tackle this problem, I have integrated RxJS (ReactiveX) into my application in search of a suitable solution. The Angular as ...

Is there a way to horizontally center Material UI Switch and its icon props?

I'm using Material-UI to implement a Switch component on my project. This particular component allows for the addition of icons, however, I've encountered an issue with alignment when including them. Is there a way to horizontally center align b ...

React.js - Using functions as a React child is not allowed

I recently started learning React.js but I'm stuck on a problem. I keep receiving this warning message: Functions aren't valid as a React child. This might be due to returning a Component instead of from render. Or maybe you intended to call this ...

Is it feasible to maintain a persistent login session in Firebase without utilizing the firebase-admin package through the use of session cookies?

Currently, I am integrating Firebase into my next.js application for user login functionality. The issue I am facing is that users are getting logged out every time they switch paths within the site. Even though their session cookie has not expired, if the ...

"Converting a regular JavaScript array into a JSON object: A step-by-step

I have an array that currently looks like this: ['service1', 'service2', 'service3'] and I want to convert it into something like: [ {'id':'1', 'serviceName':'service1'}, {'id& ...

Error with XMLHTTPRequest loading in beforeunload/unload event handlers in iOS 13.4.1 encountered

Currently, I am utilizing XMLHTTPRequest for data posting in JavaScript. Previously, it functioned smoothly on Safari and Chrome browsers up to iOS 13.3.1. However, upon updating to the latest OS version, iOS 13.4.1, an error message stating "XMLHTTPReques ...

Show live camera feed upon loading in IOS/Objective-C without using the image picker controller

Instead of showing a static photo image when asking for a profile picture, I want the screen to open with a live camera view right away. After that, I don't mind using the uipickercontroller to capture the photo, but I prefer the user to see something ...

Getting the value of an injected variable in a Vue.js computed method

I have utilized the provide/inject mechanism to pass data from a parent component to its grandchildren. However, in one of my components, I need to manipulate the data before rendering it in the template. My current setup looks like this: export default d ...

Obtaining the MapOptions object from a map using Google Maps API version 3

Previously in Google Maps api v2, you were able to retrieve map parameters like the type and zoom directly from the map object. However, in version 3, the setOptions method is used to configure parameters, but there is no equivalent method like getOption ...

Using Vue.js to loop through and display a set of images from the assets directory using v-for

I have a collection of 100 images from 1.png to 100.png stored in my assets folder. I am looking to dynamically display them using v-for without having to manually specify each individual image URL. <div v-for="n in 100"> <img :src="`../asset ...

JSF CommandLink malfunctions on Firefox when reRendering an entire form

I am currently working on a JSF 1.2 application (Sun RI, Facelets, Richfaces) that was previously designed only for IE6 browsers. However, we now need to extend our support to include Firefox as well. On one of the pages, there is a form with a button tha ...

Demonstration of utilizing browserify with Node.js, Express, and EJS

Struggling with browserify implementation on my web app. I ran browserify in the terminal to generate the bundle.js file. Placed it in the public/javascripts directory and included it in my EJS file, but encountering issues: Terminal input: browserify p ...

Navigating with Express and Vue

Currently, I am working on a basic web page that has an index '/' and a 404 page to handle errors at '/404'. In my express app setup, I have the following configuration: // Entry Point app.use("/", express.static(resolve(__di ...

React - Unable to update value in input field

I am creating a table using data fetched from an API using axios get. In the table, there is an input field with a value pulled from the axios data. However, when I type in this input field, the value does not change. For instance, if the input contains th ...

How can I ensure my AngularJS Controller variable is accessible across all page contexts?

Working with AngularJS, I have a view controller where I initialize a variable called recipesData. Here is the code for the controller: (function() { 'use strict'; angular .module('myApp') .controller('Coo ...

Using C# to implement Zoom functionality in GeckoWebBrowser (GeckoFX 45) similar to that in Mozilla Firefox

Is there a way to zoom the GeckoWebBrowser similar to how it's done in Mozilla Firefox (shown in the image) using either C# or JavaScript? https://i.sstatic.net/dvHV3.png Appreciate any assistance. ...

Potential memory issues may arise when creating a QR Code and generating a PDF file in Swift 4.2

I have developed an application that generates a QR Code and creates a PDF file at the end of each cycle. However, after running the app multiple times over nearly 5 days, it seems to stop performing its other functionalities correctly. Upon closer inspe ...

Transformation from jQuery to vanilla JavaScript

Revised: A JavaScript function is embedded within a button and I am looking to transition some of its jQuery components to pure JS due to the inability to access codes with $(this). Below is my current code: function editcheck(el) { $(el).parent().p ...