How can I insert a div dynamically based on the viewport parameter? As I need help with managing banner ads that are not responsive. For example the top divs for 728x90, 970x250, 160x600 would only load if the body client width is greater than 768 or else would load a 320x50 tag div instead.
Right now I am doing on web:
<div id="ezoic-pub-ad-placeholder-100">
<script type="text/javascript"><!--
e9 = new Object();
e9.size = "728x90";
//--></script>
<script type="text/javascript" src="http://tags.expo9.exponential.com/tags/ProWrestlingcom/ROS/tags.js"></script>
</div>
However, how it should work is when screen width is less than 768 it would show my 300 x 50 instead:
<script type="text/javascript"><!--
e9 = new Object();
e9.size = "320x50";
//--></script>
<script type="text/javascript" src="http://tags.expo9.exponential.com/tags/ProwrestlingcomMobile/320x50/tags.js"></script>
UPDATE:
I created this, which logically sounds like it should work but it doesn't display anything, unless there's something wrong with my browser. Can someone check?
<script>
window.onresize = function(){
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
if ( $(window).width() <= 767) {
e9 = new Object();
e9.size = "320x50";
script.src = "http://tags.expo9.exponential.com/tags/ProwrestlingcomMobile/320x50/tags.js";
head.appendChild(script);
}else {
e9 = new Object();
e9.size = "728x90";
script.src = "http://tags.expo9.exponential.com/tags/ProWrestlingcom/ROS/tags.js";
head.appendChild(script);
}
}
</script>