Question

I have a code that opens any DispForm.aspx link into a modal dialog. The item has a link to another DispForm.aspx -- is it possible to open this on another modal?

I tried inserting the following code below <asp:Content ContentPlaceHolderId="PlaceHolderTitleAreaClass" runat="server"> in a custom DispForm.aspx

<script type="text/javascript">
$(document).ready(function(){
    setInterval(function () {
        $("a[href*='DispForm.aspx']").each(function () {
            $(this).attr("onclick", "openDialog('" + $(this).text() + "','" + $(this).attr("href") + "')");
            $(this).attr("href", "javascript:void(0)");
            $(this).removeAttr("target");
        });
    }, 900);
}
function openDialog(title, url) {
var options = {
    url: url, 
    width:650, 
    height:700,
    //autoSize: true, 
    title: ""
};
SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', options);
}

I also tried adding the code in a script editor in DispForm.aspx.

Was it helpful?

Solution

You need add the following code below <asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server"> in the custom DispForm.aspx.

<script src="https://code.jquery.com/jquery-1.12.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
    setInterval(function () {
        $("a[href*='DispForm.aspx']").each(function () {
            $(this).attr("onclick", "openDialog('" + $(this).text() + "','" + $(this).attr("href") + "')");
            $(this).attr("href", "javascript:void(0)");
            $(this).removeAttr("target");
        });
    }, 900);
});
function openDialog(title, url) {
    var options = {
        url: url, 
        width:650, 
        height:700,
        //autoSize: true, 
        title: ""
    };
    SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', options);
}
</script>
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top