Php Internet Explorer 浏览器中未显示文件预览按钮

Php file preview button is not showing in Internet Explorer browser

代码如下。 chrome 和 firefox 中显示了一个文件预览按钮,但在 IE 中未显示。

$ua = htmlentities($_SERVER['HTTP_USER_AGENT'], ENT_QUOTES, 'UTF-8');
if (preg_match('~MSIE|Internet Explorer~i', $ua) || (strpos($ua, Trident/7.0; rv:11.0') !== false)) {
// do stuff for IE
}
else{

if(strtolower($aRow["extension"])=='pdf')
{ 
$editable .="<a class=\"iframe\" href=\"javascript:viewPdf('http://{$_SERVER['SERVER_NAME']}{$script_dir}{
$aRow["path"]}');\" title=\"Preview\"><span class=\"glyphicon glyphicon-zoom-in\"></span></a>&nbsp;";
}

您的初始 if 条件阻止 Internet Explorer 呈现按钮。为了在任何浏览器上显示它,您应该将第二个 if 条件移到原始 if-else 块之外,例如:

$ua = htmlentities($_SERVER['HTTP_USER_AGENT'], ENT_QUOTES, 'UTF-8');
if (preg_match('~MSIE|Internet Explorer~i', $ua) || (strpos($ua, 'Trident/7.0; rv:11.0') !== false)) {
    // do stuff for IE
}
else {
    // do stuff for other browsers that are not IE
}

if(strtolower($aRow["extension"])=='pdf') { 
    // render the button regardless browser User Agent (UA)
    $editable .="<a class=\"iframe\" href=\"javascript:viewPdf('http://{$_SERVER['SERVER_NAME']}{$script_dir}{
    $aRow["path"]}');\" title=\"Preview\"><span class=\"glyphicon glyphicon-zoom-in\"></span></a>&nbsp;";
}