简体   繁体   中英

javascript crashing iPad browser

I have some javascript inside a function that creates and populates an image carousel. It works fine after activating it in a pop up window the first 5 or 6 times, but then it eventually crashes the browser. I think there's some kind of leak, like something inside of it needs to be deleted before it gets created again. I know it's the carousel because if I get rid of that part of the script, it no longer crashes.

Here's the carousel script:

/* carousel */

var carousel,
el,
i,
page,
slides;

carousel = new SwipeView('#wrapper', {
                         numberOfPages: slides.length,
                         hastyPageFlip: true
                         });

// Load initial data
for (i=0; i<3; i++) {
    page = i==0 ? slides.length-1 : i-1;

    el = document.createElement('span');
    el.innerHTML = slides[page];
    carousel.masterPages[i].appendChild(el)
}

carousel.onFlip(function () {
                var el,
                upcoming,
                i;

    for (i=0; i<3; i++) {
        upcoming = carousel.masterPages[i].dataset.upcomingPageIndex;

        if (upcoming != carousel.masterPages[i].dataset.pageIndex) {
            el = carousel.masterPages[i].querySelector('span');
            el.innerHTML = slides[upcoming];
        }
    }
});

This script runs every time I click a link that launches a floating window.

I found out that I needed to clear my wrapper div. In the beginning of my function call:

document.getElementById('wrapper').innerHTML = "";

Seems to work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM