Posts

Showing posts with the label JavaScript.document

document.write(shenanigans)

As I have twitted yesterday, I have discovered one of the most weird JavaScript behaviors ever thanks to the document.write method. The Problem We All Know ... document.write has been used for ages since it is basically the only way we have to create a blocking script during a page download. The advantage is that a script included via document.write could write something else in that point of the page and again via document.write . Classic examples are Google AdSense or others similar services where we would like to put in place an iframe with banners or an external service. The most known side effect of the document.write method is that if the document has been already loaded (DOMContentLoaded or onload event) it could " destroy " our web page erasing everything and showing nothing except what we wrote via this method. This means that every time we include in our page an external resource, we should be sure this resource will be included synchronously otherwise we could...