doujianzi8521 2016-01-15 07: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 09: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条)

报告相同问题?

悬赏问题

  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错