search
HomeWeb Front-endH5 TutorialProblems and solutions encountered in mobile H5 development

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)

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])
}

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, '/')

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
This article is reproduced at:segmentfault. If there is any infringement, please contact admin@php.cn delete
H5: How It Enhances User Experience on the WebH5: How It Enhances User Experience on the WebApr 19, 2025 am 12:08 AM

H5 improves web user experience with multimedia support, offline storage and performance optimization. 1) Multimedia support: H5 and elements simplify development and improve user experience. 2) Offline storage: WebStorage and IndexedDB allow offline use to improve the experience. 3) Performance optimization: WebWorkers and elements optimize performance to reduce bandwidth consumption.

Deconstructing H5 Code: Tags, Elements, and AttributesDeconstructing H5 Code: Tags, Elements, and AttributesApr 18, 2025 am 12:06 AM

HTML5 code consists of tags, elements and attributes: 1. The tag defines the content type and is surrounded by angle brackets, such as. 2. Elements are composed of start tags, contents and end tags, such as contents. 3. Attributes define key-value pairs in the start tag, enhance functions, such as. These are the basic units for building web structure.

Understanding H5 Code: The Fundamentals of HTML5Understanding H5 Code: The Fundamentals of HTML5Apr 17, 2025 am 12:08 AM

HTML5 is a key technology for building modern web pages, providing many new elements and features. 1. HTML5 introduces semantic elements such as, , etc., which enhances web page structure and SEO. 2. Support multimedia elements and embed media without plug-ins. 3. Forms enhance new input types and verification properties, simplifying the verification process. 4. Offer offline and local storage functions to improve web page performance and user experience.

H5 Code: Best Practices for Web DevelopersH5 Code: Best Practices for Web DevelopersApr 16, 2025 am 12:14 AM

Best practices for H5 code include: 1. Use correct DOCTYPE declarations and character encoding; 2. Use semantic tags; 3. Reduce HTTP requests; 4. Use asynchronous loading; 5. Optimize images. These practices can improve the efficiency, maintainability and user experience of web pages.

H5: The Evolution of Web Standards and TechnologiesH5: The Evolution of Web Standards and TechnologiesApr 15, 2025 am 12:12 AM

Web standards and technologies have evolved from HTML4, CSS2 and simple JavaScript to date and have undergone significant developments. 1) HTML5 introduces APIs such as Canvas and WebStorage, which enhances the complexity and interactivity of web applications. 2) CSS3 adds animation and transition functions to make the page more effective. 3) JavaScript improves development efficiency and code readability through modern syntax of Node.js and ES6, such as arrow functions and classes. These changes have promoted the development of performance optimization and best practices of web applications.

Is H5 a Shorthand for HTML5? Exploring the DetailsIs H5 a Shorthand for HTML5? Exploring the DetailsApr 14, 2025 am 12:05 AM

H5 is not just the abbreviation of HTML5, it represents a wider modern web development technology ecosystem: 1. H5 includes HTML5, CSS3, JavaScript and related APIs and technologies; 2. It provides a richer, interactive and smooth user experience, and can run seamlessly on multiple devices; 3. Using the H5 technology stack, you can create responsive web pages and complex interactive functions.

H5 and HTML5: Commonly Used Terms in Web DevelopmentH5 and HTML5: Commonly Used Terms in Web DevelopmentApr 13, 2025 am 12:01 AM

H5 and HTML5 refer to the same thing, namely HTML5. HTML5 is the fifth version of HTML, bringing new features such as semantic tags, multimedia support, canvas and graphics, offline storage and local storage, improving the expressiveness and interactivity of web pages.

What Does H5 Refer To? Exploring the ContextWhat Does H5 Refer To? Exploring the ContextApr 12, 2025 am 12:03 AM

H5referstoHTML5,apivotaltechnologyinwebdevelopment.1)HTML5introducesnewelementsandAPIsforrich,dynamicwebapplications.2)Itsupportsmultimediawithoutplugins,enhancinguserexperienceacrossdevices.3)SemanticelementsimprovecontentstructureandSEO.4)H5'srespo

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

Video Face Swap

Video Face Swap

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

Hot Tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

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

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!