You would need to send an ajax request and then perform the actions in Javascript. Or have a form that the user is forced to submit to send in their data (you can get the data using Javascript)
There is no way of knowing the screen size before rendering
Normally you would use css media queries to change the look