function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Pablo GarciaPablo Garcia 

Odd behaviour getting the window width in a Visualforce page in Salesforce1 (only iPhone)

I am writing a Visualforce page that contains some HTML <div> elements whose width depend on the device screen width. The code runs well in all browsers, except in Salesforce1 in iPhone (in iPads it's ok). I am using this js command to get the window width:
$( window ).width();
This command is call when loading the page, but different results. Sometimes is 414 and sometimes 519 (in an iPhone 6).

Does anybody know the cause of this odd behaviour?

Thanks!
 
Best Answer chosen by Pablo Garcia
Pablo GarciaPablo Garcia
Thanks for the answer. 

Finally, I found a solution for this issue: I am using 
window.screen.width;

instead of 
 
$( window ).width();

 

All Answers

Zuinglio Lopes Ribeiro JúniorZuinglio Lopes Ribeiro Júnior
Hello Pablo,

It's hard to tell extacly what might going on with that. Either way, if you're trying to detect the CSS media query there are better solutions to be considered and if you are only trying to detect the real viewport size of your window you should take into account all the variables.

Please refer to the links below, they might be helpful:

http://stackoverflow.com/questions/19291873/window-width-not-the-same-as-media-query
http://matanich.com/2013/01/07/viewport-size

Regards.

Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.
Pablo GarciaPablo Garcia
Thanks for the answer. 

Finally, I found a solution for this issue: I am using 
window.screen.width;

instead of 
 
$( window ).width();

 
This was selected as the best answer