doujianzi8521 2016-01-14 23:58
浏览 70
已采纳

如何在Laravel PHP中获取客户端DOM宽度

I don't know if this is even possible, but I'd appreciate any help.

  • How do I get the client's DOM width in Laravel?
  • Basically, is there a way to extract the client's screen width from the $request?
  • Or are there any functions in Laravel or Blade that will give me a screen width value?

I know that I can get the DOM width with jQuery $(document).width(), but I need the width value on server side; before any js is executed.

  • 写回答

2条回答 默认 最新

  • duanliu8998 2016-01-15 01:13
    关注

    @ArturGrigio You can try set JavaScript cookie and access it in Laravel. When user visits your website, get the screen size with JS (window.width) and store it in a cookie screen=WxH In Laravel $screen = Cookie::get('screen');

    $screen = explode("x", $screen);
    $width = $screen[0]
    $height = $screen[0];
    

    This is 1 solution to do it.

    Unfortunately the is no way to get screen size info from PHP. You can try to play around with User Agent and detect if it is a mobile or desktop or tablet. and make fix sizes for those 3 types.

    A good User Agent package for Laravel

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?