I have a responsive site that responds to 3 different sizes, mobile, tablet and laptop.
I have an Ad which appears only when the viewport is <= 625:
if ( adWidth <= 625 )
google_ad_size = ["100", "50"];
document.write (
'<ins class="adsbygoogle" style="display:inline-block;margin-top:45px;width:'
+ google_ad_size[0] + '%;height:'
+ google_ad_size[1] + 'px" data-ad-client="'
+ google_ad_client + '" data-ad-slot="'
+ google_ad_slot + '"></ins>'
);
So when the page is loaded the ad wont appear when unless it's <= 625.
The problem is that when you resize the browser the Ad won't disappear unless you refresh the page, this is a problem because it breaks my heading making it unreadable.
I have some jQuery which detects if media queries are a being used:
function media_query(obj) {
size = obj();
if (size != currentSize) {
if (size == 'tablet') {
var refesh = document.getElementById('sglHead');
$('#sglHead').html(refresh);
currentSize = 'tablet';
}
}
}
$(window).resize(_.debounce(function () {
media_query(mqCSS);
}, 10));
As you can see I've attempted to do it with .html() but no luck:
The container itself looks like this:
So how can I refresh the contents of <header id="sglHead">
when the media query "tablet" is true?