1

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.

1
  • I guess content editor approach will work... Just make sure you are using correct syntax... Writing callback functions and all. Dec 19, 2018 at 2:20

1 Answer 1

2

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>
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.