doushe2513 2015-08-08 02:54
浏览 17
已采纳

试图通过PHP发送window.width(POST上的空白页)

I am trying to figure out a way to save and then echo or print_r the window.innerwidth and window.innerheight..

I did it like below and I keep getting a blank page

first page

<html>

<body>


<form action='trythis2.php' method='POST'>
<input type='hidden' id='dimensions' name='dimensions'>

<input type='submit' value='submit'>
</form>

<script type="text/javascript">

$(window).resize(function() {
    $("#dimensions").html($(window).width());
}).resize();

</script>

</body>

</html>

Second page

<?php


$thisis = $_POST['dimensions'];

print_r($thisis);


?>

and on the POSTED page its just blank no text or anything. I wanted it to show my browsers width.

  • 写回答

1条回答 默认 最新

  • duanliao5995 2015-08-08 03:01
    关注

    Use val() to set or retrieve the value of input field. html() is used to set inner html of html elements. Hope this will help.

    Svae this code as .php extension

    Code:

        <?php
    
        if(isset($_POST['dimensions'])){
    
        $thisis = $_POST['dimensions'];
    
        echo $thisis;
    
        exit();
    
        }
    
        ?>
    
        <html>
        <head>
    
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    
        </head>
    
        <body>
    
        <form action='' method='POST'>
        <input type='hidden' id='dimensions' name='dimensions'>
    
        <input type='submit' value='submit'>
        </form>
    
        <script type="text/javascript">
    
        $("#dimensions").val($(window).width());
    
        $(window).resize(function() {
            $("#dimensions").val($(window).width());
        });
    
        </script>
    
        </body>
        </html>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码