【发布时间】:2013-09-13 13:11:22
【问题描述】:
我想显示一张图片。
在“Windows Surface RT”上,它必须是 580 像素。
在所有其他设备中,它必须是 413 像素。
我正在使用这段代码来检测操作系统:
var OSName="Unknown OS";
if (navigator.appVersion.indexOf("Win")!=-1) OSName="Windows";
if (navigator.appVersion.indexOf("Mac")!=-1) OSName="MacOS";
if (navigator.appVersion.indexOf("X11")!=-1) OSName="UNIX";
if (navigator.appVersion.indexOf("Linux")!=-1) OSName="Linux";
但我无法在 jquery 中检测到设备类型。所以我使用了这个php代码。
//Get Device Info
$mobile = new Mobile_Detect;
$deviceType = ($mobile->isMobile() ? ($mobile->isTablet() ? 'tablet' : 'phone') : 'computer');
$scriptVersion = $mobile->getScriptVersion();
我不想将我的 index.html 更改为 index.php。
那么有没有办法有一个单独的 php 文件,并在 index.html 头标签中添加它?
【问题讨论】:
-
假设您有正当理由不想简单地重命名文件 .php,实际上可以在 html 文件中运行 PHP,但您必须修改 htacess 文件,否则页面将被发送直接进入浏览器,无需解析 PHP。只需将以下内容添加到您的 htacess 或根据需要进行编辑...
AddType application/x-httpd-php .html