Click here to Skip to main content
15,888,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

Hoping someone can provide some help.

I am using Wordpress along with an ajax theme and I am also using an ajax search plugin.

In order to stop the page being reloaded and continue to use ajax when clicking a search result in the ajax search I have been provided with the following code:

JavaScript
    let dom_observer = new MutationObserver(function(mutation) {
    if ( typeof Pjax != 'undefined' ) {
        let newContent = document.querySelector(".asl_r");
        let pjax = new Pjax({
                   cacheBust: false,
                   elements: "a", // default is "a[href], form[action]"
                   selectors: ["title", "#header nav", "#aside", "#footer", "#content"] 
                });
        pjax.refresh(newContent);
        jQuery('.asl_r .item').off('click.body').one('click.body', function(){
            document.body.click();
        });
    }
});
let container = document.documentElement || document.body,
    config = { attributes: false, childList: true, subtree: true, characterData: false };
dom_observer.observe(container, config);


This works fine, but I have an issue where if you navigate to a page and then hit the back button in a browser the previous page will load but will start to infinitely reload, without this code I can navigate back fine.



Thanks

What I have tried:

I have tried removing cacheBust but this does not help, if someone with knowledge of js/ajax could provide any advice it would be much appreciated.
Posted
Updated 7-Jun-22 1:56am

Nothing. I have given up on this for now :)
 
Share this answer
 
Comments
Richard Deeming 7-Jun-22 9:23am    
This is not a "solution" to your question. I suggest you delete it if you want to avoid attracting down-votes.
Try this...

JavaScript
<script>
    function preventBack() {
        window.history.forward();
    }

    setTimeout("preventBack()", 0);
    window.onunload = function() {
        null
    };
</script>

answer found here...
How to disable the back button in the browser using JavaScript - Stack Overflow[^]
 
Share this answer
 
Comments
Member 11919685 2-Jun-22 10:47am    
Hi,

Thank you very much, I am trying to keep the back button function if possible though.
Disabling it would be a last resort.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900