JakubAndrysek/mkdocs-open-in-new-tab

Does not work with material navigation.instant

Closed this issue · 4 comments

ptyork commented

The "navigation.instant" feature of the material theme breaks this plugin. It works on full page load (initial load, refresh, etc.) but not after navigating an internal link.

I assume using this feature just prevents the DOMContentLoaded event from firing during internal navigation. Perhaps there is another event that can be used to trigger your *_new_window() functions? I don't know enough about what is core MkDocs vs. Material for MkDocs to even know where to start looking for this. But maybe you do. ;)

Hi, I have tried to fix it, but nothing works.
I run the JS script on page load, but it doesn't handle the page change.
If you have any ideas, please let me know.

My test code is here:

window.addEventListener('popstate', function(event) {
    // Handle the page change here
    console.log("popstate: " + document.location + ", state: " + JSON.stringify(event.state));
});

window.addEventListener('hashchange', function(event) {
    // Handle the page change here
    console.log("hashchange: " + document.location + ", state: " + JSON.stringify(event.state));
});

window.addEventListener('change', function(event) {
    // Handle the page change here
    console.log("change: " + document.location + ", state: " + JSON.stringify(event.state));
});

window.addEventListener("DOMContentSwitch", function() {
    console.log("DOMContentSwitch" + document.location);
});

window.addEventListener("DOMContentLoaded", function() {
    console.log("DOMContentLoaded" + document.location);
});

window.addEventListener("change", function() {
    console.log("change" + document.location);
});

I have added this info to README.md

Add support for instant loading - MkDocs Material.

Thanks to mkdocs_charts_plugin plugin that supports that feature.

Other mentions Mkdocs material LaTeX not rendering in instant mode of solution.