4

Is it possible to redirect a user when closing a document in the web app viewer?

In particular, I have a left menu link to .pptx documents located in the document library. When the X (close button within the web app) is clicked, the user is shown the document's library.

This behavior is unwanted. I would like to return the user to the starting location.

The pptx web app viewer opens a url similar to this:

http://client1.mydomain.com/project11210/_layouts/15/WopiFrame.aspx?sourcedoc=/project11210/Shared%20Documents/mypowerpoint.pptx&action=default

As far as I can tell, there are no query string parameters for redirection. I have tried using a web part page viewer, but the url to the page is a normal aspx page.

If I have to write JavaScript, what would it look like?

Environment:

  • SharePoint 2013 SP1 Enterprise farm
  • Windows Server 2012 R2
  • Office Web Apps Server 2013

This question is somewhat of a duplicate to (but slightly different):

redirecting when document is closed

4 Answers 4

1

You need to edit the script of master page. this is how i have achieved.

var parts = document.referrer.split('://')[1].split('/');
    var protocol = document.referrer.split('://')[0];
    var host = parts[0];
    var pathName = parts.slice(1).join('/');
    if(host=="excel.officeapps.live.com")
    {
    window.location = "where you want to redirect"
    }
0

You should modify the link on left navigation and add Source query string. So your final URL will be in following format

http://client1.mydomain.com/project11210/_layouts/15/WopiFrame.aspx?sourcedoc=/project11210/Shared%20Documents/mypowerpoint.pptx&action=default&Source=http://client1.mydomain.com
1
  • i tried that before i posted my question and it does not work. i tried it again following your example. have you been able to make it work? if so, i will keep working with it. my concern is that sopiframe.aspx does not support the Source parameter.
    – tony bonn
    Commented Nov 20, 2014 at 17:54
0

The Web App Viewer uses the WOPI Session Context url to redirect the user on closing the app. The url is stored in a cookie, aptly named "WOPISessionContext". If this value is not set, then the redirect url will default to the default view url of the library that contains the document. The url in the cookie is also sanity checked to make sure it is a valid url under the same domain as the document.

You can set the cookie yourself in javascript to make sure the close url goes to where you want:

window.document.cookie = "WOPISessionContext=http://client1.mydomain.com/project11210/default.aspx;path=/";

The url MUST be in the same domain. This won't be an issue for you specifically, but for anyone else who happens to come across this answer.

Note that this will not work if the user is clicking on a link to the document in a standard SharePoint XSLT web part for the library. This is because, the cookie will be set on click and overwrite your change.

0

there is always document.referrer Which you can add in either the masterpage or elsewhere in the front page or wherever you want to redirect from.

if(document.referrer.indexOf("WopiFrame.aspx") > 0){
  window.location.href = "http://sharepoint/sites/redirecthere";
}

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.