alot of web advertising providers use the old document.write method, in my case AdTech. Is it possible to overwrite the document.write method to defer after the onload event?
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- Can php detect if javascript is on or not?
you can output a
Notes:
document.write
code chunks.window.onload
with your javascript framework specific onload handler.Moving all your scripts to the bottom of the page (before >/body<) with advert scripts absolutely last and not using domReady at all (don't need it if your scripts are put in after all HTML elements) will do the same thing. In fact, it might be possible that defering document.write calls can even ruin the entire page depending on how aweful the advert code is.
How about using either
You can actually support script injection the correct way by intercepting calls to document.write as follows. The trick is to create a "middleman" function which checks inputs to document.write, and if it's a script tag being injected, load it correctly into the DOM instead:
Obviously this can be condensed down a bit further, but the variable names are included for clarity. If you like, you can follow up by using async and defer on the script tag loading the third-party library itself, making sure to test for correctness after such a change.
Source