2

After putting the meta name="viewport" content="width=device-width" tag in the head of my HTML file, I am getting 320 from $(window).width() in portrait mode on my iPhone 4. This is what I expected, and matches what I get from here: http://responsejs.com/labs/dimensions/ (this link was provided in another, similar, discussion on SO).

However, when I switch to landscape mode, $(window).width() continues to return 320, whereas the response.js page linked to earlier claims that $(window).width() returns 480. Out of all the "width"-based, Viewport variables listed on that response.js page (except those which depend on response.js, which I'm not using) I get 320 from all of them except window.outerWidth, which is 480. However, every single one returns 480 on that response.js page.

What am I missing here? I looked through the source of that response.js page and they simply seem to be calling $(window).width() as I am, so I'm quite mystified.

EleventyOne
  • 7,300
  • 10
  • 35
  • 40
  • After applying Munkie solution ...did this solve in the iPad as well as I am getting 768px in landscapre which is portrait width on iPad? Please reply... – Rajat Modi Jul 21 '14 at 07:50

1 Answers1

4
<meta name="viewport" content="width=device-width; initial-scale=1.0;">

Add that instead, I've tested it on my iPhone and it's output is correct. Tested it with

$(window).width();
Dan
  • 8,041
  • 8
  • 41
  • 72
  • Ah, thanks very much (I'm not able to up-vote your answer yet). I can confirm that this works for me too and, indeed, I see that the response.js page I mentioned to had that in there as well. However, the initial-scale=1.0 setting seems to be associated with a nasty [bug](https://github.com/h5bp/html5-boilerplate/issues/824) on iOS, with a [fix](https://github.com/sergiolopes/ios-zoom-bug-fix) that's a little over my head at the moment. – EleventyOne Jun 25 '13 at 17:03
  • did this solve in the iPad as well as I am getting 768px in landscapre which is portrait width on iPad? Please reply... – Rajat Modi Jul 21 '14 at 07:48