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(&quot;idAttachmentsTable&quot;);
                    if (elm == null || elm.rows.length == 0)
                    document.getElementById(&quot;idAttachmentsRow&quot;).style.display=&apos;none&apos;;
                </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>
Was it helpful?

Solution

I solved this using the code below.

<script language="javascript">
function hideIEBtn() {
    if ($.browser.msie) {
        $(&quot;div[id=ieAttachBtn]&quot;).show();
    } else {
        $(&quot;div[id=ieAttachBtn]&quot;).hide();
    }
}
$(document).ready(function() {
    hideIEBtn();
});

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top