Using opening links using document library feature

Forums vLooup for SharePoint Using opening links using document library feature

Viewing 6 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
      HYM
      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

    • #30269
      Paul Lynch
      Participant

      Hi Alex,

      Believe this is related to this post, am trying to do the opposite thing than this lady.

      When a user clicks on the Name of a file in the vlookup in a form, I want it to open the excel file in excel online, not in a _target=blank tab (which causes the file to download).

      This mimics the default SP Doc library view where if you click on the file name it opens in O365 (excel online) does not download.

      Setup – using Chrome btw and latest version of DFFS. (although would like it to force this behaviour in IE/Edge too)

      list1 and a vlookup to library1 – library1 contains excel files.

      In my list form, the vlookup uses FileLeafRef to show a link to open the excel document.

      (LinkFilenameNoMenu,LinkFilename are computed and do not appear as links)

      Guessing it might be a special function like above I need to add?

      KR
      Paul

      • This reply was modified 1 month, 1 week ago by Paul Lynch.
      • This reply was modified 1 month, 1 week ago by Paul Lynch.
    • #30274
      Paul Lynch
      Participant

      example of where where I am clicking

      Attachments:
      • #30282
        Alexander Bautz
        Keymaster

        Hi,
        You can do that by adding this to your Special configuration:

        {"function":"openInWeb"}

        and this to your Custom JS:

        function openInWeb(val, item){
            var name = item.get_item("FileLeafRef");
            var url = item.get_item("FileRef");    
            return "<a href='"+url+"?web=1' target='_blank'>"+name+"</a>";
        }

        Let me know how this works out.

        Alexander

        PS: This only works in Office 365.

    • #30286
      Paul Lynch
      Participant

      This works perfectly thank you Alex

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