Following is my code to update the price of an item on the page, but the page has some anchor tags that lead to a different url(categories of items to filter) without page refresh and since there is no page refresh, the script isnt loading. I tried turbolinks:load as well with no luck.
var $ = jQuery.noConflict();
$(document).on('ready', function() {
setTimeout(checkPaqe, 3000);
});
function checkPaqe() {
var pageType = 'NA';
pageType = (dataLayer.find(dataLayer => dataLayer.PageType)["PageType"] != null) ? dataLayer.find(dataLayer => dataLayer.PageType)["PageType"]: "NA"
if (pageType === 'ListingPage' || pageType === 'ProductPage' || pageType === 'HomePage') {
updatePrice();
}
}
function updatePrice() {
let pricetags = document.getElementsByClassName("price");
for (let i = 0; i < pricetags.length; ++i) {
var price = pricetags[i].innerHTML;
price = price.replace('$', '');
price = parseFloat(price) - 30;
price = parseFloat(price).toFixed(2);
pricetags[i].innerHTML = "<s style=\"color:red\">" + pricetags[i].innerHTML + "</s><br><span style=\"font-size: 10px;\">Your price with loyalty voucher <span style=\"font-size: 2.0em;\">$" + price + "</span></span>";
}
}
window.onhashchange = function() {
console.log('hashchange');
}
window.onpopstate = function() {
console.log('popchange');
}