search
HomeWeb Front-endHTML TutorialExample code about viewport compatibility issues

I recently developed a mobile website and encountered some problems when using viewport.

After many attempts, the current situation is that UC, Chrome, and Android automatically With the browser and safari, the viewport can be displayed according to the zoom ratio as expected.

However, in the QQ browser, which has a huge number of users, it seems that the viewport cannot be recognized (or cannot be used).

The code is as follows:

HTML

<meta id="viewport" content="
    target-densitydpi=device-dpi, 
    user-scalable=no, 
    width=device-width, 
    initial-scale=0.5" name="viewport" />

JavaScript

var viewPortScale;
var dpr = window.devicePixelRatio;
if(dpr <= 2) {
    viewPortScale = 1 / window.devicePixelRatio;
} else {
    viewPortScale = 0.5
}

document.getElementById(&#39;viewport&#39;).setAttribute(
        &#39;content&#39;, 
        &#39;user-scalable=no, 
         width=device-width, 
        initial-scale=&#39; + viewPortScale);

// alert(viewPortScale);

If you remove the alert comment, the QQ browser will pop up to display the required zoom ratio, but there is still no Scale as needed.

【Related Recommendations】


1.

Special Recommendation:"php Programmer Toolbox" V0 .1 version download

2.

Share the viewport attribute to solve the problem of the font being reset when switching from vertical screen to horizontal screen on the mobile terminal

3.

Special topic on viewport: In-depth understanding of responsive web design in css - viewport

4.

Introduction to the parameters of Viewport in HTML5 and how to use it

The above is the detailed content of Example code about viewport compatibility issues. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Python中的SVM实例Python中的SVM实例Jun 11, 2023 pm 08:42 PM

Python中的支持向量机(SupportVectorMachine,SVM)是一个强大的有监督学习算法,可以用来解决分类和回归问题。SVM在处理高维度数据和非线性问题的时候表现出色,被广泛地应用于数据挖掘、图像分类、文本分类、生物信息学等领域。在本文中,我们将介绍在Python中使用SVM进行分类的实例。我们将使用scikit-learn库中的SVM模

PHP8.0与Laravel的兼容性问题PHP8.0与Laravel的兼容性问题May 14, 2023 am 08:45 AM

近日,PHP8.0正式发布,作为一名Laravel开发者,你或许正在思考着将你的项目升级至最新版的PHP,以收获更多的特性和性能提升,但在此之前,你需要知道PHP8.0与Laravel之间存在的兼容性问题,以便更好的规避和解决这些问题。首先,我们来了解一下PHP8.0带来了哪些变化。PHP8.0最大的变化在于其对JIT(Just-In-Time)编译器的引入

CSS Viewport: 如何使用 vh、vw、vmin 和 vmax 单位来实现响应式设计CSS Viewport: 如何使用 vh、vw、vmin 和 vmax 单位来实现响应式设计Sep 13, 2023 pm 12:15 PM

CSSViewport:如何使用vh、vw、vmin和vmax单位来实现响应式设计,需要具体代码示例在现代响应式网页设计中,我们通常希望网页能够适应不同屏幕尺寸和设备,以提供良好的用户体验。而CSSViewport单位(视口单位)就是帮助我们实现这一目标的重要工具之一。在本文中,我们将介绍如何使用vh、vw、vmin和vmax单位来实现响应式设

如何使用 CSS Viewport 单位 vh 来创建适配手机屏幕的网页布局如何使用 CSS Viewport 单位 vh 来创建适配手机屏幕的网页布局Sep 13, 2023 am 11:15 AM

如何使用CSSViewport单位vh来创建适配手机屏幕的网页布局手机设备的普及和使用越来越广泛,越来越多的网页需要进行手机屏幕的适配。为了解决这个问题,CSS3引入了一个新的单位——Viewport单位,其中包括vh(viewportheight)。在这篇文章中,我们将探讨如何使用vh单位来创建适配手机屏幕的网页布局,并提供具体的代码示例。一

win10安装失败原因win10安装失败原因Feb 19, 2024 pm 11:02 PM

Win10安装失败原因随着科技的飞速发展,操作系统也在不断更新迭代,微软的Windows系统一直以来都受到广大用户的喜爱。然而,在使用Windows10操作系统的过程中,有些用户可能会遇到安装失败的情况,那么这些安装失败的原因究竟是什么呢?一、硬件兼容性问题如果你的电脑硬件配置较老旧或者不兼容Windows10操作系统的最低硬件要求,那么安装过程中很有可

Python中的VAE算法实例Python中的VAE算法实例Jun 11, 2023 pm 07:58 PM

VAE是一种生成模型,全称是VariationalAutoencoder,中文译作变分自编码器。它是一种无监督的学习算法,可以用来生成新的数据,比如图像、音频、文本等。与普通的自编码器相比,VAE更加灵活和强大,能够生成更加复杂和真实的数据。Python是目前使用最广泛的编程语言之一,也是深度学习的主要工具之一。在Python中,有许多优秀的机器学习和深度

win7驱动安装失败的原因详解win7驱动安装失败的原因详解Dec 30, 2023 pm 12:20 PM

对于一些使用Windows7操作系统的用户来说,在安装驱动程序时可能会遇到安装失败的问题。然而,很多用户对于安装失败的原因并不清楚。事实上,这种问题可能是由于驱动程序本身存在问题或与操作系统不兼容等因素导致的。下面我们一起来详细了解一下可能导致Windows7驱动安装失败的原因。win7驱动安装失败原因:一、错误的驱动程序如果我们下载的驱动程序本身存在文件错误,那么安装就会失败。在《文字玩出花》这款受欢迎的文字解谜游戏中,有一个叫做怀旧大扫除的关卡,每天都会有新的关卡更新。在这个关卡里,你需要找

Python中的GAN算法实例Python中的GAN算法实例Jun 10, 2023 am 09:53 AM

生成对抗网络(GAN,GenerativeAdversarialNetworks)是一种深度学习算法,它通过两个神经网络互相竞争的方式来生成新的数据。GAN被广泛用于图像、音频、文字等领域的生成任务。在本文中,我们将使用Python编写一个GAN算法实例,用于生成手写数字图像。数据集准备我们将使用MNIST数据集作为我们的训练数据集。MNIST数据集包含

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft