Modal Dialog Archives : Binary Bits https://blog.binarybits.net/tag/modal-dialog/ Bits & Pieces - A blog by Kannan Balasubramanian Mon, 03 May 2021 10:50:10 +0000 en-GB hourly 1 https://wordpress.org/?v=6.5.2 Open SharePoint Office documents in modal dialog https://blog.binarybits.net/open-sharepoint-office-documents-modal-dialog/ https://blog.binarybits.net/open-sharepoint-office-documents-modal-dialog/#respond Mon, 13 Nov 2017 07:38:30 +0000 https://blog.binarybits.net/?p=962 Sometimes we need Microsoft Office documents to be opened in dialogs instead of SharePoint’s default behavior which is opening the document in the same window or tab. The following code helps in implementing this. Note: This code only works for office documents. For pdf documents look at the previous article. <!-- Put this code below […]

The post Open SharePoint Office documents in modal dialog appeared first on Binary Bits.

]]>
Sometimes we need Microsoft Office documents to be opened in dialogs instead of SharePoint’s default behavior which is opening the document in the same window or tab.

The following code helps in implementing this.

Note: This code only works for office documents. For pdf documents look at the previous article.

<!-- Put this code below the list view web part -->
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.2.1.min.js">
</script>
<script type="text/javascript">
    $hrefVal = $("a[onclick*='return DispEx'][target!='_blank']").attr("href");
    $siteUrl = _spPageContextInfo.webServerRelativeUrl;

    $("a[onclick*='return DispEx'][target!='_blank']")
        .removeAttr("onclick")
        .attr("href", "javascript:OpenDocumentInDialogue(\"" + $siteUrl + "/_layouts/WopiFrame.aspx?action=default&sourcedoc=" + $hrefVal + "\")");

    function OpenDocumentInDialogue(href) {
        var o;
        $("body").append("<div id='docTemp' style='min-height:600px;min-width:800px;height:100%;overflow:hidden'><object data='" + href + "' width='100%' height='100%'></object></div>");
        o = {};
        o.html = $("#docTemp")[0];
        o.showMaximized = true;
        o.title = href.substring(href.lastIndexOf("/") + 1);
        o.dialogReturnValueCallback = OpenDocumentinDlgCallback;
        SP.UI.ModalDialog.showModalDialog(o);
    }

    function OpenDocumentinDlgCallback() {
        // do something here when the dialog closes
    }
</script>

 

The post Open SharePoint Office documents in modal dialog appeared first on Binary Bits.

]]>
https://blog.binarybits.net/open-sharepoint-office-documents-modal-dialog/feed/ 0
Open SharePoint PDF documents in modal dialog https://blog.binarybits.net/open-sharepoint-pdf-documents-in-modal-dialog/ https://blog.binarybits.net/open-sharepoint-pdf-documents-in-modal-dialog/#respond Mon, 13 Nov 2017 05:43:59 +0000 https://blog.binarybits.net/?p=958 Sometimes we need PDF documents to be opened in dialogs instead of SharePoint’s default behavior which is opening the document in the same window or tab. The following code helps in implementing this. Note: This code only works for PDF documents. For office documents look at the next article. <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.2.1.min.js"></script> <script type="text/javascript"> $("a[href$='.pdf']").each(function() […]

The post Open SharePoint PDF documents in modal dialog appeared first on Binary Bits.

]]>
Sometimes we need PDF documents to be opened in dialogs instead of SharePoint’s default behavior which is opening the document in the same window or tab.

The following code helps in implementing this.

Note: This code only works for PDF documents. For office documents look at the next article.

<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.2.1.min.js"></script>
<script type="text/javascript">
    $("a[href$='.pdf']").each(function() {
        $(this).removeAttr("onclick").attr("href", "javascript:OpenDocumentInDialogue(\"" + this.href + "\")");
    });

    function OpenDocumentInDialogue(href) {
        var o;
        $("body").append("<div id='docTemp' style='min-height:600px;min-width:800px;height:100%;overflow:hidden'><object data='" + href + "' width='100%' height='100%' type='application/pdf' ></object></div>");
        o = {};
        o.html = $("#docTemp")[0];
        o.showMaximized = true;
        o.title = href.substring(href.lastIndexOf("/") + 1);
        o.dialogReturnValueCallback = OpenDocumentInDialogueCallback;
        SP.UI.ModalDialog.showModalDialog(o);
    }

    function OpenDocumentInDialogueCallback() {
        // Do something here when the dialog closes
    }
</script>

 

The post Open SharePoint PDF documents in modal dialog appeared first on Binary Bits.

]]>
https://blog.binarybits.net/open-sharepoint-pdf-documents-in-modal-dialog/feed/ 0