Skylar Ittner
Skylar Ittner

Reputation: 812

Perform page loads with jQuery on all normal anchor tags

I have a website here with a dark Bootstrap theme. I have tried various tricks for eliminating white flashes on page loads, but they only work about half the time.

Can I use jQuery to "intercept" links and load them asynchronously, so there is no flash?

I don't want to change the actual link format in the menu bar, etc., as that would require modifying my CMS. I can change everything about the site template except the navigation, which is generated automatically.

Upvotes: 0

Views: 27

Answers (1)

GillesC
GillesC

Reputation: 10874

You can bind all hyperlinks, or target the ones you want with the right CSS selector, and prevent the default behaviour then simply do an ajax query to get the page and do whatever you want from there.

$("a").on("click", function(event) {
    event.preventDefault();
    $.get(this.href, function(data) {
        // do stuff
    });
});

Upvotes: 1

Related Questions