2

I have an HTML page that has a number of links displayed via dropdowns / unordered lists on top of the page (using a Bootstrap 3 navbar). These links go to MS Office documents (Word, Excel, PowerPoint) that are hosted on an internal server.

By click on the links I would like to have them open within an iframe on the same page instead of using separate pages or downloads.

I tried the below but this always opens me the standard popup to either save the file or open it in a separate window.

Can someone tell me what I am doing wrong here? E.g. something in addition to refresh the iframe?

My HTML for the link dropdown (just one item):

<li type='disc'><a href='javascript:void' class='navLink' name='test.pptx'>Text</a></li>

My HTML for the iframe:

<iframe src="#" width="100%" height="auto" frameborder="0" id="iView" name="iView"></iframe>

My jQuery:

$(document).on('click', '.navLink', function() {
    var fileName = $(this).attr('name');
    var fileLocation = 'http://somefilepath/uploads/';
    var fileSource = fileLocation + fileName;
    $('#iView').prop('src', fileSource);
});

Edit

If this approach does not work is there a way to embed an MS office document in an HTML website?

halfer
  • 19,824
  • 17
  • 99
  • 186
user2571510
  • 11,167
  • 39
  • 92
  • 138

1 Answers1

5

The problem is that your web server returns your files with ''Content-disposition: attachment'' HTTP header. That prompts the Save As/Open dialog to popup. What you want is inline attachments instead.

More info here:

Content-Disposition:What are the differences between "inline" and "attachment"?

Note: that cannot be handled on the client (i.e. via JS), you will need to modify your server app.

Community
  • 1
  • 1
uncoder
  • 1,818
  • 1
  • 17
  • 20