This question probably has an easy answer, yet it evades me. In the ads on my site (Adsense or otherwise), they provide a script tag (e.g. <script type='text/javascript' src='to/my/source'></script>
) to place in the location I want the ad to appear.
However, before I load the ad script, I want to test to see if the user is on a handheld device by testing the CSS display
of a div
in js. Like this:
if ($('#mydiv').css('display') == 'none') {
//do not load the ad; do nothing
} else {
//load the ad script element at *this place*;
//that is, where this conditional is placed
}
My thought is to place this conditional in the same place as I would place the ad script normally. However, it's not working (just like I knew it wouldn't), and I can't figure out how to load the script tag in place. Thanks for the help.
EDIT:
Here is my actual code:
<script type='text/javascript'>
if ($('#sidebar-wrapper').css('display') == 'none') {
} else {
document.write("<scr" + "ipt type='text/javascript' src='http://ads.blogherads.com/bh/32/320/310566/1343256/300a.js'>" + "</scr" + "ipt>");
}
</script>