0

I have an external script which loads advertisements. The script being loaded includes calls to document.write. The problem is this delays the doc ready for the site. I would like to delay showing this until after the doc ready.

Currently I just tried wrapping the function that loads the external content in a jquery doc ready, but the page blows up. It goes to a all white screen with just the ad and some code showing.

Obviously this is because document.write is running after the page is loaded. Does anyone know a way around this or how to delay loading of the external content till after doc ready?

aefxx
  • 24,835
  • 6
  • 45
  • 55
jhanifen
  • 4,441
  • 7
  • 43
  • 67
  • The only way I know to do this is to make sure your ads load in one or more ` – Pointy Mar 01 '11 at 23:51
  • Yes that it what I switched to for the time being. Although I am worried the iframe may have disadvantages. – jhanifen Mar 02 '11 at 00:13
  • doing more research I came across this. Has anyone used it? http://jqueryad.web2ajax.fr/ – jhanifen Mar 02 '11 at 01:40

4 Answers4

1

This has been solved for you:

by the fine people behind Postscribe

Tom
  • 1,447
  • 1
  • 12
  • 26
0

You could try the hack where you override document.write and buffer the output, then write it to a div in doc ready.

Annie
  • 6,621
  • 22
  • 27
  • has anyone else used this? Is there any working examples or other usage of similar techniques online? – jhanifen Mar 02 '11 at 01:34
  • this looks promising, doing more research I have found other uses of that, such as here. http://jqueryad.web2ajax.fr/ – jhanifen Mar 02 '11 at 01:41
  • These aren't exactly the same thing described above, but I found blog posts from John Resig (http://ejohn.org/blog/xhtml-documentwrite-and-adsense/) and Steve Souders (http://www.stevesouders.com/blog/2010/12/15/controljs-part-3/) about overriding document.write, so I do think lots of people are doing it. I first heard about the technique at the Velocity conference. – Annie Mar 02 '11 at 17:34
0

@jhanifen: My first thought was of the defer attribute, which I've used before specifically when I had issues with certain scripts in Internet Explorer that used document.write. I wasn't sure if it would work so well in the context of ads loaded from external sources so I did I search on SO for it and came across this question and accepted answer -- Is it possible to load a javascript ad last on the page to prevent slow load times? -- which may prove to be / or help you towards getting your own solution.

Community
  • 1
  • 1
stealthyninja
  • 10,343
  • 11
  • 51
  • 59
0

I think this could work as well:

https://github.com/iamnoah/writeCapture

Utility to assist the Ajax loading of HTML containing script tags that use document.write

glen-84
  • 1,778
  • 2
  • 18
  • 30