Target whole page – NOT RECOMDNDED
window.addEventListener('load', function()
{
document.body.innerHTML = document.body.innerHTML.replaceAll(
"REPLACE_THIS_TAG",
"Replace with this"
);
});
WARNING!!!!!! – This rewrites the entire <body>, the browser destroys the old DOM nodes and creates new ones. If you’ve already done things that like attach click handlers they won’t work!
Target a section of the page only – BETTER APPRAOCH
Better approach, target just a specific section of the page, e.g. within a specific <div> ID:
window.addEventListener('load', function()
{
const MyContainerId = document.getElementById('MyContainerId');
if(MyContainerId)
{
MyContainerId.innerHTML = MyContainerId.innerHTML.replaceAll(
"REPLACE_THIS_TAG",
"Replace with this"
);
}
});
USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through resources like this. We hope you find it helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support here. If you need help with a problem please use one of the many online forums.
