spencery2
spencery2

Reputation: 521

How do I load a SharePoint 2013 discussion page in Reply mode?

I have a SharePoint 2013 Community Site that is used for discussions. I want to create a link to a specific discussion item that will open the discussion item in "Reply" mode, i.e. the mode you get to if you click the Reply button just under the Discussion item text. I want to do this because the Reply mode text entry box is right under the discussion item text where it is obvious to see. The default reply text entry box is at the bottom of the page and it scrolls off the page if there are already a lot of replies on the topic.

Here is the default view on a Discussion item

enter image description here

If you click the "Reply" link here

enter image description here

then the a Reply Pane opens up right under the discussion item text.

enter image description here

But what I want to do it to be able to send a URL by mail that will open the discussion thread already in Reply mode.

Upvotes: 1

Views: 1845

Answers (1)

spencery2
spencery2

Reputation: 521

The solution I found to do this consisted of customizing the /Lists/Community Discussion/Flat.aspx with client-side script as follows.

First insert a Script Editor into the page (Settings -> Edit Page -> Add a Web Part -> Categories -> Media and Content -> Content Editor -> Script Editor.

enter image description here

Next upload a copy of jquery.min.js to the Site Assets library.

Then add the following code to the Script Editor using Edit Snippet:

<script src="/SiteAssets/jquery.min.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">

 $(document).ready(function() {

    if (location.search.indexOf('replyMode=1') != -1)
    {
      openReplyPane();
    }
  });

function openReplyPane()
{
var mouseEvent = new MouseEvent("click", {
  'bubbles': true,
  'cancelable': true,
  'view': window,
  'detail': 0,
  'screenX': 0,
  'screenY': 0,
  'clientX': 0,
  'clientY': 0,
  'ctrlKey': false,
  'altKey': false,
  'shiftKey': false,
  'metaKey': false,
  'button': 0,
  'relatedTarget': null,
  'currentTarget': 'form#aspnetForm',
  'srcElement': 'a#commandBar0-reply-Link.ms-secondaryCommandLink',
  'target':'a#commandBar0-reply-Link.ms-secondaryCommandLink',
  'timeStamp':1425842811416,
  'toElement':'a#commandBar0-reply-Link.ms-secondaryCommandLink'
});

var replyLink = document.getElementById('commandBar0-reply-Link');

replyLink.dispatchEvent(mouseEvent);
}
</script>

Save your changes.

Now if you add the string "&replyMode=1" to the end of the URL for the discussion item, you can navigate to the post, and the Reply pane will be automatically opened for the user.

Upvotes: 1

Related Questions