0

I am trying to create Javascript with Objective C related application. I am rending javascript content page on UIWebview. The UIWebview content page view I want to differentiate sizes based on device model into iOS. How to make differentiate device detection using javascript.

My Code Below :

 // iPhone 3
    if (window.screen.height==480 && window.screen.width==320 && window.devicePixelRatio==1)
    { 
        $('#chartDivWrapper').html('<div id="chartdiv" style="height:300px;width:500px;"></div>');
    } 
    // iPhone 4, this is Retina
    else if (window.screen.height==480 && window.screen.width==320 && window.devicePixelRatio==2) 
    { 
        $('#chartDivWrapper').html('<div id="chartdiv" style="height:300px;width:500px;"></div>');
    } 
    // iPhone 5
    else if (window.screen.height==568 && window.screen.width==320 && window.devicePixelRatio==2) 
    { 
        $('#chartDivWrapper').html('<div id="chartdiv" style="height:400px;width:600px;"></div>');
    } 
    // iPad
    else if (window.screen.height==1024 && window.screen.width==768 && window.devicePixelRatio==1) 
    { 
        $('#chartDivWrapper').html('<div id="chartdiv" style="height:425px;width:680px;"></div>');
    } 
    // iPad Retina
    else if (window.screen.height==1024 && window.screen.width==768 && window.devicePixelRatio==2) 
    { 
        $('#chartDivWrapper').html('<div id="chartdiv" style="height:425px;width:680px;"></div>');
    } 
    // all other, this was before for all 
    else  
    { 
Apple_Ajay
  • 227
  • 3
  • 17
  • Does this work? http://stackoverflow.com/a/14223920/893578 – Sheepy Feb 19 '16 at 11:19
  • Not version buddy. I am asking different devices is there. iPhone 4 5 6 ipads. – Apple_Ajay Feb 19 '16 at 11:20
  • Device detection has been out of favour for a long time as it is generally unreliable, ineffective and high maintenance. Far better to detect features, so if you want to code for different screen sizes, detect that. You seem to have adopted that approach, though I think it is more common to use a range of sizes rather than exact numbers, e.g. `window.screen.height < 481`, etc. – RobG Feb 19 '16 at 11:40

0 Answers0