Greetings all,

I need to control ad content depending on browser width using JavaScript because although Google has a new responsive ad unit there isn't responsive textual ad unit equivalent yet. Question is simple, how can I adapt this code to perform the function correctly?

So in the <head> if I have it right the code would look something like this...

Code:
<script>
var wi = $(window).width();
	if (wi <= 500){var showAd = "nothing";} 
	else {var showAd = "<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
                        <ins class="adsbygoogle"
                             style="display:inline-block;width:468px;height:15px"
                             data-ad-client="ca-pub-xxxxxxxx"
                             data-ad-slot="xxxxxxxx"></ins>
                        <script>
                        (adsbygoogle = window.adsbygoogle || []).push({});
                        </script>";}
</script>
And in the page where I want the ads to display (or not) I put this code?

Code:
<script type="text/javascript">document.write(showAd);</script>

Can anyone help me to polish this code?

Thanks very much

JC