当前位置:网站首页>Handling of web page image loading errors
Handling of web page image loading errors
2022-07-28 04:58:00 【JINZI village grass】
In the website , There is often a situation , quite a lot picture Or because the image address itself points to an unknown address (404 Address ), Or because the image server itself failed to give img Return the correct picture file stream , It will lead to pictures error perhaps alt Information , If there is no corresponding img Set width and height , It will even affect the layout of the entire page , For the above problems , We can use the method of monitoring pictures error The event is then handled accordingly . Such as :
<img src=" Picture address " onerror="this.src=' Replace picture address '"/>According to normal logic , There will be no problem with the above processing , But it's easy to ignore a situation , That is, if the replacement image address does not exist , that onerror The code inside will be executed repeatedly , Until the picture is requested , If you can't ask all the time , That's equivalent to an endless cycle . Regarding this , Add a line of code to the above code
this.onerror=none;After performing the first image replacement , Cancel the of the picture error Event monitoring . If the above code is used jquery The implementation is as follows
$("img").each(function (index,ele) {
$(ele).one("error",function () {
$(this).attr("src"," Replace picture address ");
})
});use one The bound event will be executed only once , So there will be no dead cycle
边栏推荐
- RT_ Use of thread mailbox
- HDU 1435 stable match
- Strlen introduction, and the difference between sizeof
- Data security is gradually implemented, and we must pay close attention to the source of leakage
- [daily question 1] 735. Planetary collision
- Cmake usage base summary
- Basic knowledge of network security - password (I)
- Easycvr Video Square snapshot adding device channel offline reason display
- np. unravel_ Index() finds the index value of an element (or group of elements) of the array after being pulled into one dimension. The corresponding index value in the original dimension (or specify
- Testcafe's positioning, operation of page elements, and verification of execution results
猜你喜欢

解析智能扫地机器人中蕴含的情感元素

Analysis of the reason why easycvr service can't be started and tips for dealing with easy disk space filling

Introduction to testcafe

Dynamic SQL and paging

Program life | how to switch to software testing? (software testing learning roadmap attached)

(clone virtual machine steps)

基于MPLS构建虚拟专网的配置实验

Design and development of C language ATM system project

Real intelligence has been certified by two of the world's top market research institutions and has entered the global camp of excellence

Improving the readability of UI layer test with puppeter
随机推荐
Observable time series data downsampling practice in Prometheus
猿辅导技术进化论:助力教与学 构想未来学校
MySQL(5)
How to simulate common web application operations when using testcafe
The first artificial intelligence security competition starts. Three competition questions are waiting for you to fight
[idea] check out master invalid path problem
Improving the readability of UI layer test with puppeter
Flink mind map
Take out system file upload
Is low code the future of development? On low code platform
【CPU占用高】software_reporter_tool.exe
RT based_ Distributed wireless temperature monitoring system of thread (I)
Rendering process, how the code becomes a page (I)
[daily one] visual studio2015 installation in ancient times
(manual) [sqli labs27, 27a] error echo, Boolean blind injection, filtered injection
UI automation test farewell from now on, manual download browser driver, recommended collection
[II. Mobile web page development] 2D & 3D conversion and animation, mobile terminal layout, responsive layout
String 0123456789abcdef, what is the number of substrings (not empty and not the same string itself) [Hangzhou multi tester] [Hangzhou multi tester _ Wang Sir]
[function document] torch Histc and paddle Histogram and numpy.histogram
塑料可以执行GB/T 2408 -燃烧性能的测定吗