0

I am trying to embed a sharepoint 2010 site into a gSite (works with https) to make the site accessible also for gSite/Chrome users. To do so, I have used the following script:

Open Document Library documents in a new tab

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>

<script>

$(document).ready(
  function ()
  {
    // has to be on an interval for grouped doc libraries
    // where the actual links are loaded only once a group
    // is expanded
    setInterval(
      function ()
      {
        $("a[onclick*='return DispEx'][target!='_blank']")
          .attr("target", "_blank")
          .removeAttr("onclick");

        // document type icons
        $("td.ms-vb-icon>img[onclick]:not([documentUrl])")
          .click(function (e)
          {
            window.open($(this).attr("documentUrl"), "_blank");
            e.stopPropagation();
            e.preventDefault();
            return false;
          })
          .each(function ()
          {
            $(this).attr(
            "documentUrl",
            $.trim(String($(this).attr("onclick"))
              .split("=")[1]
              .replace(/["'{}]/g, "")
              .split(";")[0])
            );
            this.onclick = null;
          });
      },
      500
    );
  }
);

</script>

to be able to open doc/excel/powerpoint directly from side (if script is not used, the embed sharepoint just freezes, after clicking e.g. doc or excel file from the library).

  • the script works great - the embed sharepoint opens the file in a new chrome tab and redirects to IE - online sharepoint - word/excel editor, however, I would rather like to download and open the file directly in MS Word/Excel etc. (favourable action).

Is it possible to open the link in new tab and automatically download/open the file in MS word/excel, instead of online editor?

I already have changed settings to Open in the client application. Also tried to change DefaultItemOpen=1 to 0, but without any luck so far (could be because script overwrites the site properties).

Thank you!

0

Solved by adding extra. removeattr - onmousedown & onclick:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>

<script>

$(document).ready(
  function ()
  {
    // has to be on an interval for grouped doc libraries
    // where the actual links are loaded only once a group
    // is expanded
    setInterval(
      function ()
      {
        $("a[onclick*='return DispEx'][target!='_blank']")
          .attr("target", "_blank")
          .removeAttr("onclick")
      .removeAttr("onmousedown");

        // document type icons
        $("td.ms-vb-icon>img[onclick]:not([documentUrl])")
          .click(function (e)
          {
            window.open($(this).attr("documentUrl"), "_blank");
            e.stopPropagation();
            e.preventDefault();
            e.removeAttr("onclick")
        e.removeAttr("onmousedown");

            return false;
          })
          .each(function ()
          {
            $(this).attr(
            "documentUrl",
            $.trim(String($(this).attr("onclick"))
              .split("=")[1]
              .replace(/["'{}]/g, "")
              .split(";")[0])
            );
            this.onclick = null;
          });
      },
      500
    );
  }
);

</script>

Now works for Chrome users as well!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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