Never seen this before-

I was asked to add the this code to a banner notice that I was supposed to add to a Drupal 6 website I am in charge of updating:

<script type="text/javascript" src="http://eblast.siteurl.com/pathtocode"></script>

The src attribute linked to the following:

document.write('

    ') document.write('
  -  Update Friday: October 3, 2014, 03 October 2014
    ') document.write('
  -  Update Friday: October 3, 2014, 03 October 2014
    ') document.write('
   - October 10, 2014, 09 October 2014
    ') document.write('

') 

Each of the dates (Friday: October 3, 2014 , Friday: October 3, 2014, and October 10, 2014) linked to an email newsletter.

I thought this was rather curious (although I’m really way behind the times with respect to JavaScript), and was wondering if this was a normal way to have a banner on a webpage link to email newsletters.

Hi,

This technique allows vendors to easily embed inline content from a script which is external to your host/domain. It’s quite a common way to inject things like analytics code into a page.

Using document.write means that said vendors don’t have to worry about overriding already established onload events or including the necessary abstraction to add onload events safely.

You should probably be aware however, that document.write is considered bad practice by some as it is very easy to misuse. For example, if you try to use it after the document has loaded it will either overwrite the page, write a new page, or simply not work.

So although I wouldn’t say that it was a normal way to have a banner on a webpage, it is a reasonably common technique to embed inline third-party content.

You might also like to read this: Why is document.write considered a “bad practice”?