I've been looking for a question like this but none of them answer my question.
Please forgive me as I sometimes lack the ability to explain myself.
I have a page in sub1.domain.com where all links are formatted as
<a href="/link?param=whatever">
and I'm using jQuery to change the base domain to sub2.domain.com before the /link part that's different to the host to all hrefs on the page. I found this snippet while researching the issue. This is the code:
$('a').each(function() {
$(this).attr("href", function(index, old) {
return old.replace("/link", "https://sub2.domain1.com/link");
});
});
And it works like a charm for static links but the thing is that the page is a search results page that dynamically loads new results even after the page has loaded.
How do I make it dynamic so that all links that are loaded by the search, are modified by this script automatically? In other words, how do I apply this script to links that appear after the page has loaded and new results are cominig in?
base href will not work in this instance as it somehow breaks the whole page.
Thank you.