I'm presenting some Search results to the user using REST API, is there something specific should I include in the link to the document so the document opens in the browser?

  • I thought that depended on the settings of the underlying library where the document is stored, if the behavior is to open in the browser it will. Not certain about this and haven't tested. Commented Jul 28, 2015 at 20:36
  • Let's say that the link is in the home page.... I checked the library options and the option for open in the browser is activated
    – yngrdyn
    Commented Jul 28, 2015 at 20:36
  • what I mean is, if document X that is in library Y and presented on page Z, if user clicks the link, it should take the file handling options from library Y. That is my understanding in theory, I have not tried this in practice. Commented Jul 28, 2015 at 20:40
  • I said, I Checked the library and the options are fine... But still downloading the document with the link
    – yngrdyn
    Commented Jul 28, 2015 at 20:41

2 Answers 2


The simplest solution is to append ?web=1 at the and of file url


read mode:


edit mode (if user has permissions):


You can obtain the file URL and concatenate with a constant as in the following code:

    function documentWebUrl(ctx) {
        var fileUrl = ctx.CurrentItem.FileLeafRef.FileUrl;
        ExecuteOrDelayUntilScriptLoaded(function () {
            var clientContext = new SP.ClientContext();
            var web = clientContext.get_web();
            clientContext.executeQueryAsync(function (s, a) {
                var webUrl = web.get_url();
                var DOCURL = webUrl + "/_layouts/15/WopiFrame.aspx?sourcedoc=" + encodeURIComponent(fileUrl) + "&action=default";
                // here put some code to navigate or whatever you need to DOCURL ....
        }, "SP.js");
  • In general it's a sample on client side script to obtain the url in the following form <Site URL>/_layouts/15/WopiFrame.aspx?sourcedoc=<Doc URL>&action=default.
    – nilsandrey
    Commented Jul 28, 2015 at 21:43
  • 1
    better use the static object _spPageContextInfo.webAbsoluteUrl to obtain the weburl instead of using an request
    – Mx.
    Commented Jul 29, 2015 at 8:50
  • Yes, I prefer to use _spPageContextInfo.webAbsoluteUrl
    – yngrdyn
    Commented Jul 29, 2015 at 14:49

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.