Table of Contents
Round-trip caching problem
IOS does not support the format of new Date("2019-01-01 00:00:00")
WeChat QR code
Cannot be clicked on IOS
audio audio cannot be played
300ms delayed response to click event on IOS mobile terminal
Fixed problem
Home Web Front-end H5 Tutorial Problems and solutions encountered in mobile H5 development

Problems and solutions encountered in mobile H5 development

Mar 30, 2019 am 10:43 AM
javascript WeChat

The content this article brings to you is about the problems and solutions encountered in mobile H5 development. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

WeChat sharing signature error invalid signature

In vue single-page application history mode, WeChat sharing always prompts signature error invalid signature

According to the WeChat official website document, jssdk has been introduced, correct Configure a js secure domain name, and the signature generated by the backend developer is also verified by the WeChat signature tool. However, the custom sharing on the front end always reports a signature error, and there is no way to customize the sharing. If you ensure that there are no problems with the basic configuration, and the signature also passes WeChat Signature tool verification, then it may be a signature error caused by the inconsistency between the URL accessed by the front-end and the URL generated by the background.

If the front-end passes the URL to the back-end through ajax to obtain the signature, then we need to remove the current page' #'hash part of the link, and needs to encodeURIComponent

let url = location.href.split('#')[0]
encodeURIComponent(url)
Copy after login

Normally, this can achieve custom sharing on WeChat, but after the single-page application routing is switched, the IOS side still prompts a signature error, and the Android side has no problem

This is because the view in history mode is switched through pushState, but the IOS WeChat client (the Android client has been repaired) does not support the new H5 feature of pushState, so the routing changes but the WeChat browser obtains The URL has not changed. Copy the link in the upper right corner and find that the URL recorded by WeChat is still the URL when you first entered it. Unless you refresh it manually or refresh it using page jump methods such as window.location, you can get the latest URL

The solution is to record the URL when entering the page. If it is an iOS device, then use this URL to obtain the WeChat signature

router.afterEach(to => {
  sessionStorage.setItem('currentUrl',window.location.href)
})
let url = encodeURIComponent(location.href.split('#')[0])
if(system == "iOS" && sessionStorage.getItem('currentUrl')) {
  url = encodeURIComponent(sessionStorage.getItem('currentUrl').split('#')[0])
}
Copy after login

At this time, it is correct to use this URL to obtain the WeChat signature. This method is only suitable for For IOS devices, as long as the signed URL is consistent with the URL recorded by WeChat, it will be correct.

Round-trip caching problem

When you click the browser's forward and backward buttons, sometimes the js will not be automatically executed. Specifically in Safari, this has to do with round trip caching (bfcache).
Solution: window.onunload = function(){};

If it is a Vue single-page application and keep-alive is used, the page will not be refreshed. At this time, some interface requests can be made. Place it in the beforeRouteEnter method

IOS does not support the format of new Date("2019-01-01 00:00:00")

This way of writing new Date("2019-01 -01 00:00:00") is supported on the Android side, but not supported on the IOS side, and a NAN error will be reported, so you need to change new Date("2019-01-01 00:00:00") to new Date("2019/01/01 00:00:00") This form

let date = '2019-01-01 00:00:00'
date.replace(/\-/g, '/')
Copy after login

WeChat QR code

There may be multiple QR codes on a page, but long press to identify two The QR code can only recognize the last QR code. At this time, we need to control that only one QR code can appear in the visible area of ​​the page.

Cannot be clicked on IOS

span,p, etc. cannot be clicked by default Clicked label, monitoring click event click is invalid in IOS
Solution, add cursor: pointer;

audio audio cannot be played

audio.play() method can be played normally on Android devices , but it cannot be played on the IOS client. After setting the src of audio, we need to add this line of code
audio.load() to load the audio

You can check whether the audio is OK by monitoring the loadeddata method Start playing. Android is set to start playing after the audio is loaded, but there may be a slight delay on the iOS side. At this time, we can get whether the audio has started playing through audio.currentTime. If this value is greater than 0, it means that it has started playing.

300ms delayed response to click event on IOS mobile terminal

Fixed problem

In systems below ios8, when the small keyboard is activated, the position floating problem will occur. The solution is: just Add css style to the outer layer p in the middle part
position:fixed;top:50px; bottom:50px;overflow:scroll;

This article is all over here, there are more other exciting contents You can pay attention to the HTML5 video tutorial column on the PHP Chinese website!


The above is the detailed content of Problems and solutions encountered in mobile H5 development. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
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

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

deepseek image generation tutorial deepseek image generation tutorial Feb 19, 2025 pm 04:15 PM

DeepSeek: A powerful AI image generation tool! DeepSeek itself is not an image generation tool, but its powerful core technology provides underlying support for many AI painting tools. Want to know how to use DeepSeek to generate images indirectly? Please continue reading! Generate images with DeepSeek-based AI tools: The following steps will guide you to use these tools: Launch the AI ​​Painting Tool: Search and open a DeepSeek-based AI Painting Tool (for example, search "Simple AI"). Select the drawing mode: select "AI Drawing" or similar function, and select the image type according to your needs, such as "Anime Avatar", "Landscape"

gateio Chinese official website gate.io trading platform website gateio Chinese official website gate.io trading platform website Feb 21, 2025 pm 03:06 PM

Gate.io, a leading cryptocurrency trading platform founded in 2013, provides Chinese users with a complete official Chinese website. The website provides a wide range of services, including spot trading, futures trading and lending, and provides special features such as Chinese interface, rich resources and community support.

List of handling fees for okx trading platform List of handling fees for okx trading platform Feb 15, 2025 pm 03:09 PM

The OKX trading platform offers a variety of rates, including transaction fees, withdrawal fees and financing fees. For spot transactions, transaction fees vary according to transaction volume and VIP level, and adopt the "market maker model", that is, the market charges a lower handling fee for each transaction. In addition, OKX also offers a variety of futures contracts, including currency standard contracts, USDT contracts and delivery contracts, and the fee structure of each contract is also different.

Ouyi Exchange app domestic download tutorial Ouyi Exchange app domestic download tutorial Mar 21, 2025 pm 05:42 PM

This article provides a detailed guide to safe download of Ouyi OKX App in China. Due to restrictions on domestic app stores, users are advised to download the App through the official website of Ouyi OKX, or use the QR code provided by the official website to scan and download. During the download process, be sure to verify the official website address, check the application permissions, perform a security scan after installation, and enable two-factor verification. During use, please abide by local laws and regulations, use a safe network environment, protect account security, be vigilant against fraud, and invest rationally. This article is for reference only and does not constitute investment advice. Digital asset transactions are at your own risk.

gateio exchange app old version gateio exchange app old version download channel gateio exchange app old version gateio exchange app old version download channel Mar 04, 2025 pm 11:36 PM

Gateio Exchange app download channels for old versions, covering official, third-party application markets, forum communities and other channels. It also provides download precautions to help you easily obtain old versions and solve the problems of discomfort in using new versions or device compatibility.

How to copy Xiaohongshu copywriting. Graphical tutorial on how to copy Xiaohongshu copywriting. How to copy Xiaohongshu copywriting. Graphical tutorial on how to copy Xiaohongshu copywriting. Jan 16, 2025 pm 04:03 PM

Learn to easily copy Xiaohongshu copywriting! This tutorial teaches you step by step how to quickly copy Xiaohongshu video copy, saying goodbye to tedious steps. Open the Xiaohongshu APP, find the video you like, and click on the [Copywriting] area below the video. Long press the copy text and select the [Extract Text] function from the pop-up options. The system will automatically extract the text, click the [Copy] button in the lower left corner. Open WeChat or other applications, such as Moments, long press the input box, and select [Paste]. Click Send to complete the copy. It's that simple!

The difference between H5 and mini-programs and APPs The difference between H5 and mini-programs and APPs Apr 06, 2025 am 10:42 AM

H5. The main difference between mini programs and APP is: technical architecture: H5 is based on web technology, and mini programs and APP are independent applications. Experience and functions: H5 is light and easy to use, with limited functions; mini programs are lightweight and have good interactiveness; APPs are powerful and have smooth experience. Compatibility: H5 is cross-platform compatible, applets and APPs are restricted by the platform. Development cost: H5 has low development cost, medium mini programs, and highest APP. Applicable scenarios: H5 is suitable for information display, applets are suitable for lightweight applications, and APPs are suitable for complex functions.

Sesame Open Door Login Registration Entrance gate.io Exchange Registration Official Website Entrance Sesame Open Door Login Registration Entrance gate.io Exchange Registration Official Website Entrance Mar 04, 2025 pm 04:51 PM

Gate.io (Sesame Open Door) is the world's leading cryptocurrency trading platform. This article provides a complete tutorial on spot trading of Gate.io. The tutorial covers steps such as account registration and login, KYC certification, fiat currency and digital currency recharge, trading pair selection, limit/market transaction orders, and orders and transaction records viewing, helping you quickly get started on the Gate.io platform for cryptocurrency trading. Whether a beginner or a veteran, you can benefit from this tutorial and easily master the Gate.io trading skills.

See all articles