【发布时间】:2014-07-16 22:37:10
【问题描述】:
我可以使用 javascript 来确定屏幕是否是触摸设备,但我无法将其转换为 PHP 以包含特定文件。
<script>
function isTouchDevice() {
return 'ontouchstart' in window || !!(navigator.msMaxTouchPoints);
}
if(isTouchDevice()) {
document.getElementById('touch').value = 1;
} else {
document.getElementById('touch').value = 0;
}
</script>
<body>
<input type='hidden' id='touch' value='0'/>
<?php
// This is where i need help
// and yes...i know the code below is not proper php its just what i want to achieve.
-- if ([touch screen is true]) then....
include ("sections/blog_widget_mobile.php");
else {
include ("sections/blog_widget.php");
}
?>
我找不到 javascript 函数 isTouchDevice() 的 php 版本,所以我认为最好的方法是将值应用于 html 元素并尝试通过 php 检索该值。
谁能帮忙?
感谢任何建议
【问题讨论】:
-
jQuery 加载:if(touchScreen) { $("#result").load("sections/blog_widget_mobile.php"); } else { $("#result").load("sections/blog_widget.php"); }
-
navigator.msMaxTouchPoints 仅适用于 Microsoft,根据此 MS 文档 msdn.microsoft.com/en-us/library/ie/hh772144%28v=vs.85%29.aspx 将在 IE 11 中删除
-
谢谢大家。这很有帮助!
-
@Xaxd jquery 有内置功能触摸屏吗?这是 JQuery 还是 JQuery Mobile?我没有使用 jQM
-
@bagofmilk 加载是标准 jquery。使用标准 javascript 检测触摸屏:
标签: javascript php mobile touch