While I didn't find any suitable suggestions for my project, I managed to come up with a solution that worked effectively. My goal was to include a static navigation element on a webpage without it disappearing after navigation. This particular webpage was not under my control. To achieve this, I cleared the innerHtml of the body, inserted an iframe directed at the same page, adjusted its dimensions to fill the entire screen, and removed the border. By doing so, I could navigate within the iframe while ensuring my script executed in a timed interval to reinsert the navigation element post-navigation. Here is what I did:
document.body.innerHTML = '';
iframe = document.createElement('iframe');
iframe.setAttribute('id', 'iframe');
document.body.appendChild(iframe);
iframe.setAttribute('src', window.location.href);
iframe.style.height = "100%";
iframe.style.width = "100%";
iframe.style.border = "0";
function addContent(){
setTimeout(()=>{
elementToAddTo = iframe.contentWindow.document.getElementById('my-element-id')];
contentToAdd = document.createElement('div');
contentToAdd.innerHTML = `<p>My new content</p>`
elementToAddTo.insertBefore(contentToAdd, elementToAddTo.childNodes[0]);
}, 1000);
}
addContent()
In the new content section, I included an onchange event that triggered navigation and called the addContent function using window.top.addContent();
onchange="window.location.href = window.location.href.replace(/(param1=.*)/, 'param1='+myNewParamValue); window.top.addContent();">
I acknowledge that this method assumes specific circumstances and may only be effective for certain scenarios—such as modifying a parameter value. Nonetheless, I'm sharing this in case it proves helpful to someone grappling with a similar challenge.