Let us consider any Microsoft document. Office Web Apps (OWA) will help us in viewing the documents on the browser online.
For o365, OWA will be configured by default. For on premise, we have to set up a OWA server separately, and configure our server to integrate with OWA server.
For o365, You can find the OOB option to view document online when you right click on the documents. Find the below screen.
So lets see how to construct the URL.
Assuming file is placed under Documents folder.
Copy the document link and paste it on the browser URL area.
Append “?Web=1” at the end of the URL and press enter.
You will see the browser is redirecting to another page called WopiFrame.aspx which shows the document online. "http://siteurl/_layouts/15/WopiFrame.aspx?sourcedoc=<GUID>&file=<filename.extension>&action=default"
You can also see the following parameters appended to the URL.
Sourcedoc – contains the reference to the file path or document GUID.
File – file name with extension.
Action – This paremeter tells us the view mode. It can be any of the following. Default – Opens the document in readable mode and can be edited by clicking on edit document option (OR) Edit – Opens the document in edit mode.
The approach is same for all SharePoint platforms.
Please find the below screenshot which shows the document online.