How to open Word files as a popup from PHP file?

How to open Word files as a popup from PHP file?

There are some hyperlinks in my .php file and these links are related to Microsoft Word files (all files are .doc files).

If I click on any link it should open in a popup window and will show the contents of the file.

Right now when I click on a link, it opens the Word file, but I want to open a popup window where the data will be displayed – without asking anything or opening any window that prompts the user for the application to open the particular document with. Same for .pdf, .txt, .psd (photoshop document) and so on.

答案1

You can install Microsoft Word Viewer. It lets you open files without having to buy the program.

http://www.microsoft.com/en-ca/download/details.aspx?id=4

答案2

If you want a kind of behavior where the user clicks on a hyperlink and no external program opens, then you can only resort to displaying the Word files (or text, PSD, etc.) with HTML. You really have no other choice.

Anything else would require the user to have some kind of plugin (e.g. an ActiveX viewer for Windows users), which not all users might have installed. Especially with ActiveX, you'd shut out Linux and OS X users, for example.

So, what you need to do is:

  • Read the files through PHP or any other server-side processing method (something like here)
  • Convert their presentation to HTML (or SVG, HTML5 Canvas, anything else that a browser can display natively). This can be tricky, but there's no way around it.
  • Open a popup with Javascript when the user clicks the link, and show them what you generated.

相关内容