Hide element in IE in custom NewForm.aspx or EditForm.aspx
-
06-02-2021 - |
Question
In custom NewForm.aspx or EditForm.aspx, the ribbon is hidden and the following is added:
<div class="row">
<div class="colFull" id="attachmentsOnClient">
<span dir="ltr">
<input type="file" name="fileupload0" id="onetidIOFile" class="ms-fileinput" size="56" title="Name"></input>
</span>
<div id="ieAttachBtn">
<input name="Button1" type="button" value="Attach" onclick='OkAttach()' style="width: 6em; height: 1.7em" />
<span id="idSpace"></span>
</div>
<table>
<tr id="idAttachmentsRow">
<td nowrap="true" valign="top" class="ms-formlabel" width="20%">
<SharePoint:FieldLabel ControlMode="Edit" FieldName="Attachments" runat="server"/>
</td>
<td valign="top" class="ms-formbody" width="80%">
<SharePoint:FormField runat="server" id="AttachmentsField" ControlMode="Edit" FieldName="Attachments" __designer:bind="{ddwrt:DataBind('u','AttachmentsField','Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Attachments')}"/>
<script>
var elm = document.getElementById("idAttachmentsTable");
if (elm == null || elm.rows.length == 0)
document.getElementById("idAttachmentsRow").style.display='none';
</script>
</td>
</tr>
</table>
</div>
ieAttachBtn
is only needed in IE. It works without it in Chrome and Edge. Is there a way to show/hide this <div>
based on browser?
I inserted the following code after PlaceHolderAdditionalPageHead
, the alert works but the .getElementById().style.display
does not.
<script type="text/javascript">
if (/*@cc_on!@*/false) {
alert('This is IE');
document.getElementById("ieAttachBtn").style.display = "block";
} else {
alert('This is not IE');
document.getElementById("ieAttachBtn").style.display = "none";
}
</script>
Solution
I solved this using the code below.
<script language="javascript">
function hideIEBtn() {
if ($.browser.msie) {
$("div[id=ieAttachBtn]").show();
} else {
$("div[id=ieAttachBtn]").hide();
}
}
$(document).ready(function() {
hideIEBtn();
});
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange