How large is the usable area in iPad Safari

后端 未结 8 662
醉酒成梦
醉酒成梦 2020-12-24 07:44

I\'m developing a web app for the iPad, to run in Safari. I don\'t yet have an iPad to test on. Does anyone know the usable screen size - after any space for the safari/ipad

8条回答
  •  忘掉有多难
    2020-12-24 08:22

    So - on my ipad (ipad1, ios 5.1.1) I got slightly different numbers than above. Probably because the tab and bookmarks bars are showing.
    My values:

        portrait  : 768  x 900
        landscape : 1024 x 644
    

    So I wrote a javascript bookmarklet to get a proof positive result. You can email this to yourself, goto "about:blank" in safari, create a bookmark, edit it and cut/paste this code out of email :)

    When you get the bookmarklet running re-size the div until it matches the window and tada..

    
    javascript:( function(){
      "use strict";
      var bmIdVal = "ios_screen_res_test_bookmarklet";
      var bmDivSize = {
        w : 320,
        h : 240 
      };
    
      var vpMeta1 = document.createElement('meta');
      vpMeta1.setAttribute("name","viewport");
      vpMeta1.setAttribute("content",'initial-scale=1.0, user-scalable=no');
      document.head.appendChild(vpMeta1);
    
      function updateStatus(){
        statusDiv.innerHTML = "div is " + bmDivSize.w + ',' + bmDivSize.h + 
          " doc body says: " + document.body.clientWidth + "," + 
          document.body.clientHeight;
      }
    
      function resizeBmDiv(wPx,hPx){
        bmDivSize.w += wPx;
        bmDivSize.h += hPx;
        bmDiv.style.width=bmDivSize.w + "px";
        bmDiv.style.height=bmDivSize.h + "px";
        updateStatus();
      }
    
      var prevBmDiv = document.getElementById(bmIdVal); 
      if( prevBmDiv != null){
        document.body.removeChild(prevBmDiv);
      }
      var bmDiv = document.createElement("div");
      bmDiv.setAttribute("id",bmIdVal);
      bmDiv.style.cssText = 
        "position:absolute;left:0px;top:0px;background-color: #0066FF";
      bmDiv.style.width=bmDivSize.w + "px";
      bmDiv.style.height=bmDivSize.h + "px";
    
      var sizerB_w1 = document.createElement("button");
      sizerB_w1.style.cssText = "width:64px;height:64px";
      sizerB_w1.innerHTML="w+1";
      sizerB_w1.onclick = function(evt){
        resizeBmDiv(1,0);
      };
      var sizerB_w100 = document.createElement("button");
      sizerB_w100.style.cssText = "width:64px;height:64px";
      sizerB_w100.innerHTML="w+100";
      sizerB_w100.onclick = function(evt){
        resizeBmDiv(100,0);
      };
      var sizerB_h1 = document.createElement("button");
      sizerB_h1.style.cssText = "width:64px;height:64px";
      sizerB_h1.innerHTML="h+1";
      sizerB_h1.onclick = function(evt){
        resizeBmDiv(0,1);
      };
      var sizerB_h100 = document.createElement("button");
      sizerB_h100.style.cssText = "width:64px;height:64px";
      sizerB_h100.innerHTML="h+100";
      sizerB_h100.onclick = function(evt){
        resizeBmDiv(0,100);
      };
    
      var sizerDiv = document.createElement('div');
      sizerDiv.appendChild(sizerB_w1);
      sizerDiv.appendChild(sizerB_w100);
      sizerDiv.appendChild(sizerB_h1);
      sizerDiv.appendChild(sizerB_h100);
    
      var sizerB_wm1 = document.createElement("button");
      sizerB_wm1.style.cssText = "width:64px;height:64px";
      sizerB_wm1.innerHTML="w-1";
      sizerB_wm1.onclick = function(evt){
        resizeBmDiv(-1,0);
      };
      var sizerB_wm100 = document.createElement("button");
      sizerB_wm100.style.cssText = "width:64px;height:64px";
      sizerB_wm100.innerHTML="w-100";
      sizerB_wm100.onclick = function(evt){
        resizeBmDiv(-100,0);
      };
      var sizerB_hm1 = document.createElement("button");
      sizerB_hm1.style.cssText = "width:64px;height:64px";
      sizerB_hm1.innerHTML="h-1";
      sizerB_hm1.onclick = function(evt){
        resizeBmDiv(0,-1);
      };
      var sizerB_hm100 = document.createElement("button");
      sizerB_hm100.style.cssText = "width:64px;height:64px";
      sizerB_hm100.innerHTML="h-100";
      sizerB_hm100.onclick = function(evt){
        resizeBmDiv(0,-100);
      };
    
      var sizerMDiv = document.createElement('div');
      sizerMDiv.appendChild(sizerB_wm1);
      sizerMDiv.appendChild(sizerB_wm100);
      sizerMDiv.appendChild(sizerB_hm1);
      sizerMDiv.appendChild(sizerB_hm100);
    
      var statusDiv = document.createElement('div');
      statusDiv.style.cssText = "color:white;";
    
      bmDiv.appendChild(statusDiv);
      bmDiv.appendChild(sizerDiv);
      bmDiv.appendChild(sizerMDiv);
      document.body.appendChild(bmDiv);
      updateStatus();  
    })();
    

提交回复
热议问题