Tuesday, November 12, 2013

Magento Chrome back button loads Ajax URL and displays it instead of main URL

There is an issue where Chrome would cache the AJAX Url instead of the main URL because both are the same. This can be checked in the Net section when inspecting the page. The solution to this problem for me was to go to the vpager.js file and change it a little bit.

In the get result function somewhere:
if (url === "javascript:void(0);") {
            event.stop();
        } else
        {
            url = url.replace('ajax=true','');
            url = url.replace('?&','?');
            url = url.replace('&&','&');
            url = url+'&ajax=true';
          
            this.riff(url);
            event.stop();
        }

Add and modify this section
if (nextUrl != "")
        {
            $('list_next').href = nextUrl;
            $('list_next').removeClassName('next_disabled');
            $('list_next').addClassName('list_next');
        } else
        {
            $('list_next').href = 'javascript:void(0);';
            $('list_next').removeClassName('list_next');
            $('list_next').addClassName('next_disabled');
        }And :
(prevUrl != "")
        {
            $('list_next').href = prevUrl;
            $('list_prev').removeClassName('next_disabled');
            $('list_prev').addClassName('list_prev');
        } else
        {
            $('list_prev').href = 'javascript:void(0);';
            $('list_prev').removeClassName('list_prev');
            $('list_prev').addClassName('prev_disabled');
        }

And just a bit further down

            if (this.pop === false) {
                this.url = this.url.replace('ajax=true','');
                this.url = this.url.replace('?&','&');
                this.url = this.url.replace('&&','&');
                history.pushState({
                    url: this.url }

Modify as appropriate.

No comments:

Post a Comment