Rendering different parts depending on the size of the user window

I would like to check if the browser window is window.width> = 800px if so, I would like to partial A otherwise if window.width> = 800px.

I have little experience, explain my implementation options: I expect either a javascript method on the page or jQuery.

I tried

http://scottwb.com/blog/2012/02/23/a-better-way-to-add-mobile-pages-to-a-rails-site/

but 1. This does not work for me. 2. Even if that were the case, I expect it to work based on the device used, not the number of pixels.

Thank you in advance!

+4
source share
3 answers

The request will not contain data on the screen size, therefore, in general, sulfur has no way to find out what the screen width is and what answer to serve, as PinnyM mentioned in the comment.

A common practice is to use the User Agent to discover a mobile device from the server. The user agent is part of the request. This is not 100% accurate, but in most cases it may depend.

However, there are still solutions for your question - serve the page based on screen size.

The workaround is to use Javascript to determine the screen size first, and then use JS to delete the cookie. The server can read the cookie and decide which template to display.

The main repo is here: https://github.com/mattstauffer/Simple-RESS This is for PHP, but you can get this idea from the source code.

There is also an implementation of Rails: https://github.com/matthewrobertson/ress and an introduction: http://matthewrobertson.org/blog/2013/02/15/introducing-ress/

My opinion: I do not like this solution, although it is viable. A lot of work to be done, and a lot of things to take care of. Instead, I would prefer to discover the User User Agent.

+1
source

You can use Ahoy . The current_visit method contains the following information.

When someone visits your site, Ahoy creates a visit with lots of useful information.

traffic source - referrer, referring domain, landing page, search
keyword location - country, region and city
technology - browser, OS, and device type
Utm parameters - source, environment, term, content, campaign

+2
source

It seems that using an adaptive interface framework might be something to be explored. I am a big fan of the Foundation, it is very easy to use with Rails applications. And the new version of the Fund has just begun today! Check it out: http://foundation5.zurb.com/

0
source

Source: https://habr.com/ru/post/1481866/


All Articles