Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Viewpoint parameter closing tags issue

I am setting up javascript to display advertising network banner code for 728x90 on screens larger than 767. If width of screen is less, it would display the 300x250 banner code only. When I add the below code it shows nothing on web and mobile, just an empty space. I am working inside wordpress if that helps.

    <div class="container">ՙ



<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>
</div>

Original 728x90 ad code:

<script type="text/javascript"><!--
               e9 = new Object();
    e9.size = "728x90,970x250";
//--></script>
<script type="text/javascript" src="http://tags.expo9.exponential.com/tags/ProWrestlingcom/ROS/tags.js"></script>

Original 300x250 ad code:

<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>
like image 965
pwz2000 Avatar asked Oct 31 '22 03:10

pwz2000


1 Answers

Two problems with this code:

1) window.onresize will get called several times on resizing the window, resulting in the script tag being added multiple times

2) window.onresize will only get called on resize, not on load. window.onload will get called once, adding the script. So perhaps just change window.onresize => window.onload

like image 84
fhollste Avatar answered Nov 15 '22 06:11

fhollste