I created a quick, simple script for a chrome extension to add rel="noopener noreferrer"
to all links with target="_blank"
on a website.
Now the thing is (For example on Tumblr, if you scroll through your feed) if content gets loaded while browsing on the website, the script obviously wont add noopener to the link.
Now I thought of using MutationObserver but if I change the links with my script, MutationObserver would obviously recognize the change and I will get a infinte loop.
function gatherlinks() {
var input = document.querySelectorAll('a[target="_blank"]');
input.forEach(function addrelnoopener(link) {
if (link.rel != 'noopener' || addrelnoopener.rel != 'noreferrer') {
link.rel = 'noopener noreferrer';
}
});
}
Anyone has thoughts on how I could detect new links?