Javascript 屏幕宽度/高度到 PHP
我知道这不一定有任何意义,但是有没有办法在客户端上运行 javascript,找到活动浏览器的屏幕宽度/高度,然后将这些变量传递给 PHP 脚本?
所有的常识通常就是PHP >> Javascript,我想永远不要相信客户端,而且我目前找不到方法。
这是针对 .php 文件的,因此很容易阻塞,但我似乎无法执行相反的操作。
我正在努力创建一个 JSON 对象,但后来意识到我仍然需要攀爬同一堵墙。
谢谢。
作为一名业余爱好者,我发现技术之间的相互作用有些挑战性,但这让我感到有力量去了解。也许很快我就能用手来阻止异常。好吧,矩阵引用失败了,因为这是人们在第二层文字级别上所做的事情。
I know it doesn't necessarily make any sense, but is there a way to run javascript on the client, find the screen width/height of the active browser, and then pass those variables to a PHP script?
All the common knowledge is usually PHP >> Javascript, never trust the client I suppose, and I can't find a way at the moment.
This is for a .php file, so blocks easily, but I cannot seem to do the reverse.
I am working on creating a JSON object, but then realized I still have the same wall to climb.
Thanks.
I am finding the interactions between technologies somewhat challenging as an amateur, but it makes me feel powerful to know. Maybe soon I'll be able to stop exceptions just with my hands. Well, the matrix reference fails, because that is what people do on a second tier literal level.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以执行以下操作:
并提交表格。您可以使用 AJAX 来发送数据、cookie、图像等。我个人会使用 AJAX。
但是,是的,在这种情况下,您只需要相信客户的表面价值。但是,如果您正在使用该数据执行某些操作(例如创建图像或其他操作),您仍然应该验证该值是否有意义,这样您就不会最终尝试创建 1 亿像素宽的图像等。
You can do this:
and submit the form. You could use AJAX to send that data instead, a cookie, an image, etc. I personally would use AJAX.
But yes, this is a case where you'll need to just trust the client at face value. However, if you are doing something with that data (like creating an image or something) you should still validate that the value makes sense so you don't end up trying to create an image that is 100 million pixels wide, etc.
(哦,看这里,没有 AJAX :))
顺便说一句,我强烈建议不要使用
document.write
,而是使用window.onload
或您首选的 JS 库中更好的东西(例如 jQuery(document).ready(function(){ jQuery(document.body).append("the-image-as-in -my-example"); }) 在 jQuery 中)。(oh lookie here, no AJAX :))
By the way, I highly advice not to use
document.write
, instead either usewindow.onload
or something better from your preferred JS library (such asjQuery(document).ready(function(){ jQuery(document.body).append("the-image-as-in-my-example"); })
in jQuery).使用 jQuery 快速实现
Fast one with jQuery