Questa funzione non è disponibile per gli annunci AMPHTML.
Spesso è utile mostrare un'immagine durante il caricamento dell'annuncio, in particolare se l'annuncio è piuttosto grande.
1. Impostare un'immagine di caricamento
Aggiungi al codice HTML un elemento div con ID loading
:
<body style="visibility: hidden;">
<div id="loading" class="loading-image">
Loading...
</div>
<gwd-google-ad id="gwd-ad" polite-load="">
...
</gwd-google-ad>
</body>
2. Interrompere la visualizzazione dell'immagine di caricamento
Puoi nascondere o rimuovere l'immagine di caricamento con l'aggiunta di codice alla funzione handleAdInitialized
, che viene invocato dopo aver inizializzato l'annuncio. Con il caricamento "polite" attivo, tale metodo viene invocato una volta trasmesso l'evento PAGE_LOADED
(Enabler).
Nascondere l'immagine di caricamento
Il codice evidenziato di seguito consente di nascondere l'immagine di caricamento:
/**
* Handles the event that is dispatched after the Ad has been
* initialized and before the default page of the Ad is shown.
*/
function handleAdInitialized(event) {
// This marks the end of the polite load phase of the Ad. If a
// loading image was shown to the user, this is a good place to
// remove it.
document.getElementById('loading').style.display = 'none';
}
Rimuovere l'immagine di caricamento
Il codice evidenziato di seguito consente di rimuovere l'immagine di caricamento:
/**
* Handles the event that is dispatched after the Ad has been
* initialized and before the default page of the Ad is shown.
*/
function handleAdInitialized(event) {
// This marks the end of the polite load phase of the Ad. If a
// loading image was shown to the user, this is a good place to
// remove it.
document.body.removeChild(document.getElementById('loading'));
}