This example shows you how to refresh ad units on your page when the Riddle advances to the next question. Make sure to alter the script by inserting the ID of the DIVs containing your ads.

function onMessage(event) {
    if (event.data && event.data.riddleEvent) {
        var riddleData = event.data.riddleEvent;
        if ('object' === typeof (riddleData)) {
            // Reload iframe
            $('#google-ads-iframe').attr('src', $('#google-ads-iframe').attr('src'));
            // Pure JS - no jQuery
            //document.getElementById('google-ads-iframe').contentWindow.location.reload(true);
        }
    }
}
window.addEventListener("message", onMessage, true);

Learn more here: https://www.riddle.com/blog/refresh-quiz-ad-units/

The blog post above also explains in detail how to use the ad refresh script in various environments like WordPress, so please head on over there if you get stuck.

Leave a Comment