The following javascript returns the viewport of a browser:
<script>
$(document).ready(function(e) {
showViewportSize();
});
$(window).resize(function(e) {
showViewportSize();
});
function showViewportSize() {
var the_width = $(window).width();
var the_inner_width = window.innerWidth;
$('#width').text(the_width);
$('#inner_width').text(the_inner_width)
}
</script>
The browser can display the value via
<span id="inner_width"> Resize me </span>
How can width or innerWidth be invoked in a rails condition within a view file, assuming one wants to generate an image_tag based on the initial viewport width:
<% if width > 1440 %>
<%= image_tag(...
<% elsif width <= 1440 && width > 1200 %>
<%= image_tag(...
<% else %>
<%= image_tag(...
<% end %>
display: nonein your css based on viewport width, etc. - but you can't do what you're specifically asking.