4

When we click on the document link (Title of document) from library view,Document will open in browser(IF office web app is configured) or its get download.

But I want to open document on modal dialog.

How we can achieve this?Any idea?

  • you want it on the document library view itself or a custom page which has list of documents ? – Gautam Sheth Oct 26 '16 at 6:10
  • I want it on document library view.But if you have any script to do it on any custom page that would also helps. – Akshay Belure Oct 26 '16 at 6:12
  • I don't think that you can open a document in modal dialog. If it's a Word or Excel file, it can open in the Web App, but that will always be in a new browser tab. If you open it in Word or Excel, then consider that to be the "modal" window. – teylyn Oct 26 '16 at 6:18
4

Try this script

    $('a.classname').click(function(){
    var dlgOptions = { url:'/Lists/List Name/Name of File.pdf', autoSize: true, autoSizeStartWidth: 550 }; 
    SP.UI.ModalDialog.showModalDialog(dlgOptions);
    return false;
    })
  • so by this @ali the one particular file will be forced to be open a modal window, whereas any other files will open as normal (preset). ?! – Bucki Oct 26 '16 at 7:25
  • this is just a hint you can say, to get other file you can use the anchor object and fetch the file name and set in url. – akbar ali Oct 26 '16 at 7:27
  • lol that is too high-end dev. talk which I don't understand, salam. – Bucki Oct 26 '16 at 7:32
  • @akbarali is this code will work in the display template? If I create a custom template, map properties, and use this code; is it gonna work as it supposed to? Thanks! – YogaPanda Nov 7 '16 at 21:17
0

Though I haven't done this, and I cannot say if it will work, but I think you can do the below to get it work:

  1. Create a rich text column on the document library.
  2. Identify and take note of the query string params of OWA page when viewing an office file.
  3. Write an event receiver or using SPD workflow, set the value of this column to be an anchor and href attribute will point to javascript method which calls the SP Modal Dialog, while calling the method pass the identified params in step 2, to the URL of OWA page as query string.

HTH..

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.