Note that there are some explanatory texts on larger screens.

plurals
  1. POPrevent script from reloading again
    primarykey
    data
    text
    <p>I've made a script like an infinite loading script. Everything works fine when you scroll from top to bottom. Things go wrong when I click a product and hit the browser back button to go back to the page with the infinite loader. All products are loaded again. </p> <p>After some searching I found this <em>could</em> be bevause of the <code>document.ready</code> function is triggered again. Problem is that all other scripts aren't working anymore. My next own suggestion was to empty the div where the products are loaded in before they are loaded. Problem now is that only the first or last product of the next page is loaded.</p> <p>Does anyone know a solution or maybe can point me to some directions?</p> <p>My full loader script -></p> <pre><code>&lt;script type="text/javascript"&gt; var currentPage = {{ collection.page }}; var collectionPages = {{ collection.pages }}; var category = '{{ collection.internal.url }}'; var appendProduct = function(product) { if(currentPage == 1){ return false } //$(".collection-more").html(""); $('&lt;div class="product"&gt;&lt;/div&gt;').html(product).appendTo($(".collection-more")); var i = 1; $('.product').each(function() { if(i++ % 3 == 0) $(this).addClass('last'); }); }; var loadProducts = function() { var url = "http://www.hioshop.nl/"+category+"/page"+currentPage+".ajax"; $.getJSON(url,function(data) { $.each(data.products, function(index, product) { var imageUrl = product.image.replace('50x50x2', '180x150x2'); var itemHtml = '' + '&lt;a href="' + product.url + '" title="'+ product.fulltitle +'"&gt;&lt;img src="'+imageUrl+'" width="180" height="150" alt="'+product.fulltitle+'" title="'+product.fulltitle+'" /&gt;'; if(product.data_01 === 'sale'){ itemHtml = itemHtml + '&lt;div class="labels sale"&gt;&lt;/div&gt;'; } if(product.data_01 === 'nieuw'){ itemHtml = itemHtml + '&lt;div class="labels nieuw"&gt;&lt;/div&gt;'; } itemHtml = itemHtml + '&lt;/a&gt;' + '&lt;div class="info"&gt;' + '&lt;h3&gt;' + '&lt;a href="' + product.url + '" title="'+ product.fulltitle +'"&gt;' + product.fulltitle + '&lt;/a&gt;' + '&lt;/h3&gt;' + '&lt;div class="price"&gt;' + product.price.price_money + ''; if(product.price.price_old){ itemHtml = itemHtml + ' &lt;span&gt;' + '&lt;del&gt;' + product.price.price_old_money + '&lt;/del&gt;' + '&lt;/span&gt;'; } itemHtml = itemHtml + '&lt;/div&gt;' + // price '&lt;div class="gridAddToCart"&gt;' + '&lt;a class="button grey" href="'+product.url+'" title="'+product.fulltitle+'" rel="nofollow"&gt;'+'&lt;span&gt;Details&lt;/span&gt;&lt;/a&gt;' + '&lt;div style="margin-top:2px;"&gt;&lt;/div&gt;' + '&lt;a class="opener button blue" href="{{ 'cart/add/' | url }}'+product.vid+'" title="'+product.fulltitle+'" rel="nofollow"&gt;&lt;span&gt;In winkelwagen&lt;/span&gt;&lt;/a&gt;' itemHtml = itemHtml + '&lt;/div&gt;' + // gridAddToCart '&lt;/div&gt;' + // info '&lt;div class="clear"&gt;&lt;/div&gt;' + '&lt;/div&gt;'; appendProduct(itemHtml) }); $("#overlay").fadeOut(); $(window).scroll(function() { update(); }); }); }; loadProducts(); var isUpdating = false; var update = function() { if($(window).height() + $(window).scrollTop() &gt;= $(document).height() - 2000) { if(currentPage &lt; collectionPages &amp;&amp; !isUpdating) { isUpdating = true; currentPage++; $("#overlay").fadeIn(); $(window).unbind('scroll'); setTimeout(function(){ loadProducts(); setTimeout(function(){ isUpdating = false; }, 100); }, 100); } } }; $(window).scroll(function() { update(); }); &lt;/script&gt; </code></pre> <p><strong>UPDATED</strong> Complete code</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload