Using opening links using document library feature

Forums vLooup for SharePoint Using opening links using document library feature

Viewing 3 reply threads
  • Author
    Posts
    • #27050
      chgrnet
      Participant

      Some time back I think you gave me some code that allowed me to define certain files shown using the “document library” feature with vLookup to open these files as files, not take the browser over. This works perfectly.

      I am using FileLeafRef as the link to open the file, and some files are images. Is there a way to make any of the links (including images) visible open in a new window and not takeover the browser?

    • #27071
      Alexander Bautz
      Keymaster

      To help you I need to see the code you are using now – can you attach it here?

      Please ensure you don’t include any sensitive information in the code snippet.

      Alexander

      • #27073
        chgrnet
        Participant

        I just sent you an email with the code I am using to force certain file types to download.

        The title of this post is incorrect, so sorry about that. It should be: Opening links in a new window using the document library feature

      • #27075
        chgrnet
        Participant

        Your emailed code worked perfectly, thank you!

    • #27252
      MYH
      Participant

      hi, can you please share the script?
      thank you

    • #27407
      Alexander Bautz
      Keymaster

      Use this in the Special configuration textarea in your vLookup setup:

      {"function":"showDownloadBtn"}

      Then add this to your forms (all forms where you use vLookup) and if you use vLookup in a list view also add the function to the view (wrap it in a <script> tag and put it in a script editor web part in the page):

      function showDownloadBtn(a, b) {
          var c = [], iArr = ["doc", "docx", "xls", "xlsx", "pptx"], v = b.get_item("FileLeafRef"), ext = v.split(".").pop();
          if ($.inArray(ext, iArr) > -1) {
              // Proper method for other browsers - will open it in IE and not trigger a download
              c.push("<a href='" + b.get_item("FileDirRef") + "/" + v + "' download>Download</a>");
          }else{
              // All other documents open in a new tab
              c.push("<a href='" + b.get_item("FileDirRef") + "/" + v + "' target='_blank'>"+ v +"</a>"); // This will show the doc name - replace "+ v +" with the text Download if you like
          }
          return c.join("");
      }

      Alexander

Viewing 3 reply threads
  • You must be logged in to reply to this topic.