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 = '';
   var adVertical = '';
   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

window.onorientationchange = detectOrientation;

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