Background I've created a simple workaround to get a fixed background to work on iPad and iPhone devices, i.e creating an empty div just after the body tag with position:fixed rather than background-attachment:fixed which these devices doesn't support. All variations on the body element I've tried, like pseudo ::before is not working on these devices. An empty div solves this.
Problem
My script below works perfectly on my main page ('Home'/'Start'). But I also have other pages like 'Contact' and such, sharing the same 'global' head tag where the script lies, where it doesn't work (the div simply doesn't show up). I would expect this to add a div after each body element, regardless of which page is loaded... Also, I'm using window.onload
as I can't manually add the script after the body tag. Each subpage body tag has its own id but why would that matter? What am I missing?
window.onload = function FixedBg() {
var body = document.body;
var bgDiv = document.createElement('div');
bgDiv.className = "fixedBackground";
body.insertAdjacentElement('afterbegin', bgDiv);
}
I don't have access to manually add divs directly into the DOM which obviously would have been the approach otherwise, hence the JavaScript...