Refresh a Div That Has a Google Ad Inside It

Refresh a Div that has a Google ad inside it

As both of the other answers state, refreshing your AdSense advertisements automatically isn't allowed. I understand that you only intend to refresh the ad in response to user action, but it still isn't allowed, even though it should be!

Remember, the reason why you want to update the advertisements is so that you can show new ones. Displaying an advertisement is called an "impression." When you use code to refresh the ads, you are automatically generating ad impressions.

AdSense Program Policies state (emphasis mine):

Invalid Clicks and Impressions

Clicks on Google ads must result from genuine user interest. Any method that artificially generates clicks or impressions on your Google ads is strictly prohibited. These prohibited methods include but are not limited to repeated manual clicks or impressions, using robots, automated click and impression generating tools, third-party services that generate clicks or impressions such as paid-to-click, paid-to-surf, autosurf, and click-exchange programs, or any deceptive software.

Refreshing your advertisements is a violation of the letter of the rule against generating impressions. With that said, I think any reasonable person would agree that refreshing advertisements in an AJAX app in response to user behavior (e.g. in response to a click) isn't a violation of the spirit of the rule.

For example, imagine rewriting your entire app to stop using AJAX. That's clearly a worse experience for your users (it's slower, the page flashes on every click, the page can't dynamically update in the background), but, by a technicality, it's not a violation of the AdSense Program Policies.

Clearly Google meant to prohibit automatically replacing the advertisements every five seconds (creating a "slideshow" of advertisements). Google also meant to prohibit making your site look more attractive to advertisers by appearing to have more visits than you actually have. I'm sure they didn't intend to prevent you from designing a high-performance AJAX website... but unfortunately sometimes rules have unintended consequences.

Of course, as you originally pointed out, you CAN still refresh your advertisements if you embed them in an iframe and modify its location. (Here's how to use iframes in an AJAX application to refresh AdSense.)

You rejected iframes in your initial question, perhaps because you knew that using iframes would violate Google's policies... but if you insist on breaking the rules, you might as well break them all the way! ;-)

Ultimately, I think you'll find that generating impressions this way isn't worth the risk: you'll "refresh" the ads only to find that Google is just showing you the exact same ads as before.

Refreshing an ad-banner in a div container

Try using AJAX instead of Document.write. . doc.write will remove everything in the dom before adding new stuff..

 $.ajax({
url: "http://ad.de.doubleclick.net/adj/oms.skol.de/localnews_bilder;oms=localnews_bilder;reg=;nielsen=3b;dcopt=ist",
dataType: "script",
cache: true,//This will decide whether to cache it or no so that it will not add the timestamp along with the request
success: function(){}//In the success handler you can write your code which uses resources from this js file ensuring the script has loaded successfully before using it
});

GPT reload ad in the same div element

This may be useful for someone else in the future. Not sure if it's the best approach, but it works.

I'm destroying the slot with the method provided by gpt and also clearing the container element and the data-google-query-id attribute!

<!DOCTYPE html>
<html>
<head>
<script async='async' src='https://www.googletagservices.com/tag/js/gpt.js'></script>
<script>
var myAddSlot
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
</script>

<script>
googletag.cmd.push(function() {
myAddSlot = googletag.defineSlot('/6355419/Travel/Europe/France/Paris', ['fluid'], 'div-common-ad-container')
.addService(googletag.pubads());
googletag.enableServices();
});
</script>
</head>
<body>
<div id='div-common-ad-container'></div>
<button id="refresh">refresh</button>
<script>
googletag.cmd.push(function() { googletag.display('div-common-ad-container'); });
document.querySelector('#refresh').addEventListener('click', function () {
googletag.destroySlots()
document.querySelector('#div-common-ad-container').setAttribute('data-google-query-id', '')
document.querySelector('#div-common-ad-container').innerHTML = ''
googletag.cmd.push(function() {
myAddSlot = googletag.defineSlot('/6355419/Travel/Europe', ['fluid'], 'div-common-ad-container')
.addService(googletag.pubads());
googletag.enableServices();
googletag.display('div-common-ad-container');
});
})
</script>
</body>
</html>

How do I refresh a DIV content?

To reload a section of the page, you could use jquerys load with the current url and specify the fragment you need, which would be the same element that load is called on, in this case #here:

function updateDiv()
{
$( "#here" ).load(window.location.href + " #here" );
}
  • Don't disregard the space within the load element selector: + " #here"

This function can be called within an interval, or attached to a click event

How to refresh div in javascript, which has another script as body?

I say my idea or suggest.
I had one situation but there was the script with document.write() and this is not that you used.
Info: my answer (I was writing before the update's question)

2. idea
In your case

  <script language="javascript">  
window.setInterval("refreshDiv()", 60000);
function refreshDiv(){
document.getElementById("advert_div").innerHTML;
}
</script>

The document.getElementById("advert_div").innerHTML miss = as what?

Example

document.getElementById("advert_div").innerHTML="<p>Welcome</p>"

EDIT:

You can create the element with

document.getElementById("advert_div").innerHTML="";
var src1 = 'script',
script1 = document.createElement('SCRIPT');
script1.type="text/javascript";
script1.src = src1;
document.getElementById("advert_div").appendChild(script1);

This is a banal example but you can create the function in every banner and create the function:

"use strict";
var name = "foo";
var func = new Function(
"return function " + name + "(){ alert('sweet!')}"
)();

//call it, to test it
func();

Info:

function refreshDiv(){  

document.getElementById("advert_div").innerHTML="";
//Calling the function using the if
}

Now I do not know exactly what you want to do and I writing my ideas.
Good luck and if you seek help.

Show a div if only google ad is present

Just include this tag in your header code like so.

<script type='text/javascript'>
googletag.defineSlot('AdSlot-name', [AdSize],
'div-gpt-ad-1346196436229-0').addService(googletag.pubads());
googletag.pubads().collapseEmptyDivs();
</script>

The tag you add is:

googletag.pubads().collapseEmptyDivs();

How can refresh only a div which contains google chart and php?

I think I solve it:

google.charts.load('visualization','current', {'packages':['corechart','bar'], 'language': 'en'});
google.setOnLoadCallback(drawBigChart);
function drawBigChart() {
var jsonData = $.ajax({
url: "get_new_data.php",
dataType: "json",
async: false
}).responseText;

var data = new google.visualization.DataTable(jsonData);
var options = {something for visualisation}
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));

chart.draw(data, options);
}

AND

    $(document).ready(function(){
$("#dash_kullanicisayisi").load('kullanicisayisi.php')
$.ajax({
'url': 'get_new_data.php', // url should return only JSON data
'dataType': 'json',
'async': true
}).success(function(result) {
//Draw the chart again with the updated data
drawBigChart(result);
});
},60000);
});

solves my problem. Now chart refresh and populate new datas.
Thank for your assistances.



Related Topics



Leave a reply



Submit