+ 3
How do I make document.write() write over everything else?
I want to use it in my Infinity Shop code bit
4 Respuestas
+ 3
Maybe removing all elements from the body before running document.write will achieve what you want.
Here is a snippet that will remove all children from body:
while (var x = document.querySelector('body > *')) {
x.parentElement.removeChild(x);
}
If that isn't what you want, consider writing into an element that overlaps all content on your page.
The following example doesn't use document.write but it should make a new element that overlaps everything on the page:
let e = document.createElement('div');
e.style.position = 'fixed';
e.style.top = '0';
e.style.left = '0';
e.style.width = '100vw';
e.style.height = '100vh';
e.style.zIndex = '1000';
e.style.backgroundColor = 'rgba(255, 255, 255, 0.8)';
e.style.textAlign = 'center';
e.style.fontSize = '60px';
e.innerHTML = 'This will overlap everything.';
document.querySelector('body').appendChild(e);
If you have control over some HTML, try adding this to create a blank element:
<div style="position:fixed;top:0;left:0;width:100vw;height:100vh;z-index:1000;background-color:rgba(255,255,255,0.8);text-align:center;font-size:60px">
</div>
I experimented with putting a script in there to do document.write but the text didn't become part of the div's innerHTML.
+ 3
Ok thanks, I'll try it
+ 3
You may be mentioned in VXGEJF: The Game because I'll try using the first code to fix a problem.
+ 3
That code worked! I ended up naming the function thanksUserJoshGreig()