AJAX - Post client side screen width to server side php file [Closed]

Registration date
Thursday August 29, 2019
Last seen
August 29, 2019
 Blocked Profile -

I have done this and it works fine but it's not really efficient picking up the screen width when the orientation of the device has changed (IT DOES) but is a bit slow but works perfectly

$(document).ready(function() {
var width;
width = $(window).width();
var screenWidth = width;
method: "POST",
url: "menu.php",
data: {
screenWidth : width
success: function (res) {
I'm aware of orientationchange function but not quite sure how to piece it together with say for example device that don't have an orientation change such as desktop/ laptop devices

Does anyone have a better/ more efficient way of doing this (posting the client's screen width to a server-side PHP script) including for orientation change?

1 reply

Query the client to find what type of browser the client is using, or theOS itself.

Use $user_agent

Desktop versions can be trapped and therefore do not need to scrubbed for orientation.

Subscribe To Our Newsletter!

The Best of CCM in Your Inbox

Subscribe To Our Newsletter!