2017-01-18 94 views
1

代碼如下。有一個文件預覽按鈕,它在Chrome和Firefox中很好地顯示,但在IE中沒有顯示。在Internet Explorer瀏覽器中未顯示Php文件預覽按鈕

$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;"; 
} 

回答

1

您的初始if條件阻止Internet Explorer呈現按鈕。爲了在任何瀏覽器上顯示它,您應該將原始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;"; 
} 
相關問題