开发者

Problem with .load and.html - trying to refresh a div to display googleAdSense

开发者 https://www.devze.com 2023-03-11 18:04 出处:网络
relatively new to jQuery so could do with some help. Basically I have a thumbnail scroller, which - upon click - loads the larger version into an empty div on the same page.

relatively new to jQuery so could do with some help.

Basically I have a thumbnail scroller, which - upon click - loads the larger version into an empty div on the same page.

Now, above that image, I also have an empty div for googleAdSense banners. Ideally, i want the banner to change everytime the thumbnail is clicked in order to maximise impressions.

I have tried the .load and .html method but neither seem to be working.

.load method

$(document).ready(function(){
    $("#thumbnailImages li a").click(function(event) {
        event.preventDefault();
        var image= $(this).attr('href');
        $('#largeImage img').attr('src',image);
        $('.activeThumbnail').removeClass('activeThumbnail');
        $(this).addClass('activeThumbnail');
        $('#bannerAdvert').load('test.html');
        });  
});

And then in test.html, I have the googleAdSense code below...

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>test</title>
<script type='text/javascript' src='http://partner.googleadservices.com/gampad/google_service.js'>
</script>
<script type='text/javascript'>
GS_googleAddAdSenseService("ca-pub-12345678");
GS_googleEnableAllServices();
</script>
<script type='text/javascript'>
GA_googleAddSlot("ca-pub-12345678", "Live_HeaderBanner");
&l开发者_开发知识库t;/script>
<script type='text/javascript'>
GA_googleFetchAds();
</script>
</head>
<body style="margin: 0; padding: 0;">
<script type='text/javascript'>
GA_googleFillSlot("Live_HeaderBanner");
</script>
</body>
</html>

Now - this method DOES work when i just have plain HTML in the file. But as soon as I add the script it opens up a new window and then is just blank. When navigating to the test.html page itself, the banners are displaying fine.

.html method

I've also tried injecting the google code via the .html method

$('#bannerAdvert').html('<script type='text/javascript'>
GA_googleFillSlot("Live_HeaderBanner");
</script>');

But it doesn't like some of the characters or something as only displays brackets/braces.

If anyone could point me in the right direction it would be greatly appreciated!


I re-built my response.

Refreshing a google ad manually creates invalid impressions and is not allowed. What you are looking for is Google Adsense for Ajax. I found this information from the following question:

Refresh a Div that has a Google ad inside it

0

精彩评论

暂无评论...
验证码 换一张
取 消