Help Center Manage Your Account Technical

How do I detect device orientation for iPhone/iPad?

In this example, you have two interstitial ad versions. One is a vertical ad for portrait mode and one is a wide ad for landscape mode. Other types of ad format can be done similarly. You want to display the correct ad depending on how the device is handled.
<script type="text/javascript">
function detectOrientation() {
   var chosenAd;
   var adHorizontal = 'http://g.adspeed.net/ad.php?do=inter&aid=123&wd=-1&ht=-1&int=5&cls=20&wai=0';
   var adVertical = 'http://g.adspeed.net/ad.php?do=inter&aid=456&wd=-1&ht=-1&int=5&cls=20&wai=0';
   if (typeof window.onorientationchange != 'undefined') {
      if (window.orientation==0) { // portrait
         chosenAd = adVertical;
      } else if (window.orientation==90 || window.orientation==-90) { // landscape
         chosenAd = adHorizontal;
      } // fi
      document.write('<scr'+'ipt type="text/javascript" src="'+chosenAd+'"></scr'+'ipt>');
   } // fi
}

detectOrientation();
window.onorientationchange = detectOrientation;
</script>

Other Articles in Technical

Solve technical issues while working within the ad server

Cannot find an answer for your question? Ask our Customer Care team

Related