The specs of your browser in your desktop are the same as in the smartphone? Maybe some bug or resolution issue caused this error due different browsers versions or you are not updating the data correctly.
You can check the viewport using the following code:
function viewport(display) {
if(display) {
// Width and height
var height = $(window).height();
var width = $(window).width();
// Screen resize listener
$(window).resize(function() {
height = $(window).height();
width = $(window).width();
console.log('Height: '+height+' Width: '+width);
});
}
}
viewport(true);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
You could check the info about $.width()
here (http://api.jquery.com/width/).
If you are somehow working with responsiveness, you could opt to use CSS instead Javascript. There are plenty of tutorials and articles about this (http://learn.shayhowe.com/advanced-html-css/responsive-web-design/) that may interest you. Also, you could use some frameworks like Bootstrap (http://getbootstrap.com/) to handle this for you.
Hope that helps (: