Bug about OnResize event in Chrome browser

Source: Internet
Author: User

I used the OnResize event when I wrote the plugin, and after repeated testing, I found that the event was executed in Chrome and Opera (the kernel is basically the same as Chrome, the following collectively referred to as Chrome) when the browser is opened, which may not be counted as a bug. It is estimated that their engineers think that the window has changed when the browser is opened. I searched for the relevant content before I solved the problem, and there was really a problem with Chrome's onresize, but it was a lot different from the problems I encountered. I abstract the problem into the following function:

    function init () {        alert (' a ');         function () {            init ();                    }    }    Init ();

You can test it yourself, pop up two alert in Chrome, and the other browser pops up only one alert, because the OnResize event is executed when the Chrome browser opens. So the question now is how to get the init () function to execute only once when the Chrome browser is open.

The problem seems to be easy but tricky. Because this bug is only available when the browser is opened, it is somewhat of a trivial issue. Originally intended to let go of this problem, but I am the pursuit of perfect people, encountered problems will always try to solve. Let me sigh, a lot of questions like brain teasers, turn a bend can solve. All right, nonsense. Say, directly paste code, according to my previous practice, I still first fold the code, please everyone to solve their own way, perhaps better than my method, welcome message.

    function init () {        var width = window.innerwidth;        Alert (' a ');         function () {            var width2 = window.innerwidth;             if (width = width2) {                init ();}}    }    Init ();
View Code

I think I played a little bit smarter when it comes to solving this problem, or at least it's impossible to disable the OnResize event when the Chrome browser opens. So I added a window width as a contrast, so that the init () function is guaranteed to execute only once. Here is a small problem, I initially use a high contrast, but I do not know why two height values are biased, you can change the width to a high test, want to know this small problem friend told me.

Finally paste my plugin address https://github.com/nzbin/CardShow, I also introduced in the previous article some of the other issues in the plugin, interested friends can be viewed in the top page of the top article.

Bug about OnResize event in Chrome browser

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.