jQuery + document.write + ajax

Showing 1-2 of 2 messages
jQuery + document.write + ajax Don 4/24/09 11:23 AM
Hi Folks,
by clicking on a link I want to reload a skyscraper banner. The code
for the skyscraper banner is in a file_with_the_banner.html I want to
include this file with jquery ajax.

I have this code in the index.html

<script type="text/javascript">
        $(function() {
          $('a').click(function() {
            $('<div id="info" />').load(file_with_the_banner.html
#bannercode, function() {

                        return false;

<div id="skyscraper"></div>
<a>Load new Banner</a>


and the code in the file_with_the_banner.html

<div id="bannercode">
<script type="text/javascript">
document.write('<scr'+'ipt language="javascript1.1"
src="......URL....;loc=100;target=_blank;grp='+var1+';misc='+new Date

The problem is, that the new banner doesn't appear. When I open the
file_with_the_banner.html directly in the browser, the banner appears.
I think that jquery has a problem with document.write.

Does anyone know how to solve this issue??
Re: jQuery + document.write + ajax Ricardo 4/24/09 4:34 PM
document.write() doesn't work after the body has loaded, if you use it
the page will go blank. I was going to suggest using $.getScript()
instead, but I assume the banner script which is being loaded from
file_with_the_banner also uses document.write, so it wouldn't matter.

I suggest you look over a document.write replacement:

Or if you're feeling lazy just use an iframe (shitty solution).