diff --git a/htdocs/core/ajax/ajaxdirpreview.php b/htdocs/core/ajax/ajaxdirpreview.php
index 2389a681000535eef087c440ce8639be77a57c27..e2ad29b8562098170737142bee4d9021357dfd2a 100644
--- a/htdocs/core/ajax/ajaxdirpreview.php
+++ b/htdocs/core/ajax/ajaxdirpreview.php
@@ -213,30 +213,42 @@ if ($type == 'directory')
             $textifempty = $langs->trans('NoFileFound');
         }
         else $textifempty=($showonrightsize=='featurenotyetavailable'?$langs->trans("FeatureNotYetAvailable"):$langs->trans("ECMSelectASection"));
-        
+
         $formfile->list_of_documents($filearray,'','ecm',$param,1,$relativepath,$user->rights->ecm->upload,1,$textifempty,$maxlengthname,'',$url);
     }
 }
 
-if (! empty($conf->use_javascript_ajax) && empty($conf->global->MAIN_ECM_DISABLE_JS))
+
+if ($section)
 {
-    if ($section)
-    {
-    	$param.=($param?'?':'').(preg_replace('/^&/','',$param));
-
-        require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
-        $useglobalvars=1;
-        $form = new Form($db);
-        $formquestion=array('urlfile'=>array('type'=>'hidden','value'=>'','name'=>'urlfile'));
-        print $form->formconfirm($url,$langs->trans("DeleteFile"),$langs->trans("ConfirmDeleteFile"),'confirm_deletefile',$formquestion,"no",'deletefile');
-
-        // Enable jquery handlers on new generated HTML objects
-        print '<script type="text/javascript">'."\n";
-        print 'jQuery(document).ready(function() {'."\n";
-        print 'jQuery(".deletefilelink").click(function(e) { jQuery("#urlfile").val(jQuery(this).attr("rel")); jQuery("#dialog-confirm-deletefile").dialog("open"); return false; });'."\n";
-        print '});'."\n";
-        print '</script>'."\n";
-    }
+	$useajax=1;
+	if (! empty($conf->dol_use_jmobile)) $useajax=0;
+	if (empty($conf->use_javascript_ajax)) $useajax=0;
+	if (! empty($conf->global->MAIN_ECM_DISABLE_JS)) $useajax=0;
+
+	$param.=($param?'?':'').(preg_replace('/^&/','',$param));
+
+	if ($useajax || $action == 'delete')
+	{
+		$urlfile='';
+		if ($action == 'delete') $urlfile=GETPOST('urlfile');
+
+		require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
+		$useglobalvars=1;
+		$form = new Form($db);
+		$formquestion=array('urlfile'=>array('type'=>'hidden','value'=>$urlfile,'name'=>'urlfile'));
+		print $form->formconfirm($url,$langs->trans("DeleteFile"),$langs->trans("ConfirmDeleteFile"),'confirm_deletefile',$formquestion,"no",($useajax?'deletefile':0));
+	}
+
+	if ($useajax)
+	{
+		// Enable jquery handlers on new generated HTML objects
+		print '<script type="text/javascript">'."\n";
+		print 'jQuery(document).ready(function() {'."\n";
+		print 'jQuery(".deletefilelink").click(function(e) { jQuery("#urlfile").val(jQuery(this).attr("rel")); jQuery("#dialog-confirm-deletefile").dialog("open"); return false; });'."\n";
+		print '});'."\n";
+		print '</script>'."\n";
+	}
 }
 
 // Close db if mode is not noajax
diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php
index 0559c7b56daa20bb1188ec62dd7f43ca844b8788..9c0968436d3e4784792a90078d6490bc0266a0dc 100644
--- a/htdocs/core/class/html.formfile.class.php
+++ b/htdocs/core/class/html.formfile.class.php
@@ -813,7 +813,12 @@ class FormFile
 						else
 							$filepath=$file['name'];
 						*/
-						print '<a href="'.(($useinecm && ! empty($conf->use_javascript_ajax) && empty($conf->global->MAIN_ECM_DISABLE_JS))?'#':$url.'?action=delete&urlfile='.urlencode($filepath).$param).'" class="deletefilelink" rel="'.$filepath.'">'.img_delete().'</a>';
+						$useajax=1;
+						if (! empty($conf->dol_use_jmobile)) $useajax=0;
+						if (empty($conf->use_javascript_ajax)) $useajax=0;
+						if (! empty($conf->global->MAIN_ECM_DISABLE_JS)) $useajax=0;
+
+						print '<a href="'.(($useinecm && $useajax)?'#':$url.'?action=delete&urlfile='.urlencode($filepath).$param).'" class="deletefilelink" rel="'.$filepath.'">'.img_delete().'</a>';
 					}
 					else print '&nbsp;';
 					print "</td>";