How to turn off double tap zoom feature in Safari on iOS devices

As I work on developing my web browser game, I encountered an issue with Safari iOS where double tapping triggers a magnifying glass feature:

https://i.sstatic.net/B2y2L.png

I have been trying to disable this feature but so far, no luck. I attempted using user-select: none (specifically -webkit-user-select: none for Safari), touch-action: none, and various ways of using event.preventDefault().

While there are resources available on how to hide it for long press events (where -webkit-user-select: none does work) and how to prevent double tap zoom, I have not yet found a method to hide this magnifying glass during a double tap gesture.

Is there a solution for this problem?

Answer №1

If you're using a game with an embedded WkWebView, there's a setting in the web view configuration that can be used to turn off interactive text features. This disables things like text selection, double-tapping, and pinch-to-zoom. However, keep in mind that this setting will affect all text interactions, so use it carefully.

let config = WKWebViewConfiguration()
let view = WKWebView(frame: .zero, configuration: config)
view.configuration.preferences.isTextInteractionEnabled = false

If your website is accessed through Mobile Safari, you have the option to intercept specific element events using the touchend and touchcancel events. But, be aware that this approach may cause other unintended consequences, such as preventing events from bubbling up or interrupting event chains (e.g., the click event of the same element).

const eventParams = { passive: false };
document.body.addEventListener('touchcancel', ignore, eventParams);
document.body.addEventListener('touchend', ignore, eventParams);

function ignore(e) {
  e.preventDefault();
}

As far as I know, there isn't a way to disable these features using only CSS.

Answer №2

Here's how I tackled the issue specifically for Safari:

initialize();
canvas.addEventListener("touchend", e => playGame(e));
canvas.addEventListener("touchstart", e => playGame(e));
canvas.addEventListener("touchmove", e => playGame(e));

document.body.addEventListener('touchstart', (e) => e.preventDefault(), { passive: false });

In most cases, you can simply include this line of code :

document.body.addEventListener('touchstart', (e) => e.preventDefault(), { passive: false });

Additionally, if adding e.preventDefault() within the playGame(e) function doesn't work for me.

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

Is it possible to clear a div using jQuery and then restore its contents?

In my setup, I have a video player within a div where clicking the play button (.video-play-container) fades in the video, and clicking the close button (.close-video) fades it out. The issue arose when the faded-out video continued playing in the backgr ...

The mysterious workings of the parseInt() function

As I begin my journey to self-teach JavaScript using HeadFirst JavaScript, I've encountered a minor obstacle. The chapter I'm currently studying delves into handling data input in forms. The issue arises when I attempt to utilize the updateOrder( ...

I am looking to develop a customizable table where the user can input their desired information

Looking to create an HTML page featuring a 10x10 table with alternating red and green squares. After loading the page, a pop-up window will prompt the user to input a word, which will then appear only in the red squares of the table. While I've succes ...

Retrieve information from the database upon clicking the submit button

My table is not getting data from the database when I click a button. I tried using this code but it returned an error. <div class="wrapper wrapper-content animated fadeInRight"> <div class="row"> <div class="col ...

Can you explain the significance of Pageset to me?

I've been searching online but haven't found a definitive answer yet. Can someone explain the concept of Pageset to me? When someone mentions including code in Pageset, what exactly are they talking about? ...

Struggling to align materialUI input or textfield horizontally

import {Input} from 'material-ui'; import Select from 'react-select'; I've been trying different ways to adjust the margins and padding, even wrapping them in divs, but I can't seem to get Material UI textfield or input alig ...

The JSX Configuration in TypeScript: Comparing ReactJSX and React

When working with Typescript and React, it's necessary to specify the jsx option in the compilerOptions section of the tsconfig.json file. Available values for this option include preserve, react, react-native, and react-jsx. { "compilerOptions": { ...

If the variable is empty, use jQuery ajax to send a request with different data

Below is the code I have written: $(document).ready(function() { cookieanimalid =($.cookie("cookieanimal")); $.ajax({ type: 'POST', url: "/myurl/", data: {cookieanimalid}, success: function ( ...

sending data from angular controller to a node server

Having trouble with my Angular controller that posts to the node server. The function triggering the post is giving me a 404 (Not Found) error when running it. I've tried rewriting the post multiple times but can't seem to locate the issue. If ...

I'm struggling to find the perfect configuration for Vite, JSconfig, and Aliases in Visual Studio Code to optimize Intellisense and Autocomplete features

After exclusively using PHPStorm/Webstorm for years, I recently made the switch back to Visual Studio Code. The main reason behind this decision was the lightweight nature of VSCode and its widespread availability as a free tool, unlike paid services. I s ...

Passing JSON data from an Angular.js frontend to a Node.js backend is

Whenever I try to send a JSON object from my angular.js frontend to the node.js backend, I keep getting this error message: TypeError: Cannot read property username of undefined. I am also using Express in my project. Frontend (Angular.js): var username_ ...

Are HTML/CSS/JavaScript adjustments made after DOM loading taken into consideration in Google search results?

When searching on www.google.com, do the listings display content directly from the original HTML page load or do they also consider any front-end CSS / JavaScript stylings/adaptations? -- In a hypothetical scenario, let's examine the following ques ...

IE7, IE6 display margins differently compared to other browsers

Can anyone help with an issue I'm having with a CSS ul list menu? #header-container #header ul.top-nav { float: left; margin: 20px 0 20px 10px; } #header-container #header ul.top-nav li { float: left; margin-right: 8px; border-rig ...

Implementing dynamic data filtering in Vue.js is a valuable feature that

I'm working on a Vuejs project where I need to filter out only the questions with reviewed:true and get the count of them. However, I'm encountering an error while using the code below: TypeError: question.reviewed.includes is not a function. Can ...

Effective ways to engage with a window that is supervised by a different controller?

Although the question may appear vague initially, I struggled to find a better way to convey my idea. Let me elaborate on it in detail. In my SPA application, I have MasterController connected to the <html> tag. This MasterController consists of all ...

Issue with Bootstrap 4 Navbar collapsing and not expanding again

Help needed! My navigation bar collapses when the window is resized, but clicking on the hamburger icon does not open it back up. I have included my code below. Can someone please provide guidance on how to expand the collapsed navbar? <html lang=&quo ...

What is the best way to position HTML grandchildren using CSS Grid Lines?

I am looking to use CSS grid to create a section divided into 3 areas: header (yellow), body (red), and controls (blue). Each area will have its own div as the grid item, with children elements within these divs. https://i.sstatic.net/A367O.png Is it pos ...

Designing the button outline variant with Material-UI styling

I've recently started using Material UI and I'm facing some difficulties. One of the challenges I'm encountering is with a button component export default function TheButton(props: PropsWithChildren<Props>) { const { className, hover ...

Removing data with sweetalert in a Ruby on Rails application

Hey there, I'm currently exploring the use of sweet alert js to enhance the appearance of my alert boxes. In my table, I have a specific data deletion feature that is triggered by a standard JavaScript alert confirmation. However, when attempting to i ...

Adjust the text positioning to be lower without affecting the placement of the image

Hey experts: I'm experimenting with something, but can't quite grasp the concept... My main Div contains a paragraph of text and an image (each nested in their own Divs) at the top of the HTML page. The image is styled to float right while stylin ...