Closed nanook21 closed 6 years ago
I played around with it for a while. Basically, you can't reassign window
or window.location
. So I don't think this will work.
Would it be possible to regex replace the content that comes back from the Ajax request before it gets processed?
If I'm not mistaken, assigning window.location
doesn't make an AJAX request, it reloads the page completely.
I had meant the Ajax call that Pjax makes when loading in a new page. That comes back as a string of content doesn’t it?
So if all references to window.location in that string were replaced, window.location would never end up in the dom.
v0.2.6 will have a new pjax.handleResponse()
method that you can use to do that.
If you want to try it now, you can install from Github. With NPM, that would be npm install --save moox/pjax@master
.
Then you can do something like this:
pjax._handleResponse = pjax.handleResponse;
pjax.handleResponse = function(responseText, response, href) {
if (responseText.contains("window.location") {
// Fix the response here
}
pjax._handleResponse(responseText, response, href);
}
Great, thanks!
Would it be possible to have pjax regex replace window.location calls into PJAX calls if they are on the same host?
I have some sites that I don't control the raw code, just the CMS and header/footer, and realized that it is using window.location in some weird places.