简体   繁体   中英

Forcing the browser to open file in default viewer

I've got a small internal app that pulls data from a table. One piece of that data is a field called image_location .

An example value would be:

\\\\192.168.13.8\\audits in process\\Nat Penn 4 - 0925232\\Images\\DWB_2589060000.tif

When a data entry screen is loaded by the user, I'd like a popup to pop and display. When trying this:

function poponload(){
    var url = "\\\\192.168.13.8\\audits in process\\Nat Penn 4 - 0925232\\Images\\DWB_2589060000.tif";

    testwindow = window.open(url, "mywindow", "location=1,status=1,scrollbars=1,width=900,height=900");
    testwindow.moveTo(0, 0);
}

I get this window: 在此处输入图片说明

When I manually go to the location in my browser, it prompts me to open or save 在此处输入图片说明 :

My questions -

  1. Am I able to force the browser to display the file in it's native program?
  2. Do I have to set up my "source" server that houses all the files to handle this?

Thanks.

Look at that URL in the screenshot; 192.168.13.9/\\\\192.168.13.8 . I really doubt that is what you wanted and hence your 404 .

It might resolve itself if you put in a protocol, eg http: , but this is really due to how a URI is formatted differently to a path on a Windows machine; you probably want (notice the direction of slashes)

"http://192.168.13.8/audits in process/Nat Penn 4 - 0925232/Images/DWB_2589060000.tif"

http: is the "scheme", read protocol
// means the next part of the URI is the "authority", read domain
192.168.13.8 is an IP address, ie. an "authority"
/ signifies the beginning of the next component of the URI, the path

If you want to read more about URI syntax, the is the official RFC3986 (section 3 will be interesting).

As for making a browser display it, if a browser doesn't know how to render it natively, you'd either need to get a third party plugin for that browser on the client's machine, or display it in some other format that the browser can handle.

If the browser doesn't know how to handle it itself, it will prompt the user with the Open/Save dialogue, as you saw when manually entering the URL.

Unless I've missed something, being able to open a separate program without first prompting the user would be a massive, collosal, and [fit any other synonym here] security hole. In short, No.

Looks to me like that URL you're calling is trying to find it inside 192.168.13.9. You should probably change the url variable so that it starts with http:// , to force the browser to recognize as external. That should force the browser to handle the image like it normally would. Unfortunately, I don't think any browsers will render .tif images in-browser, and you can't force the browser to do something outside of itself from inside a webpage.

I'm not exactly sure this is what you want but...

If the "popup" your trying to display is the browsers save/open popup that you show pops up when entering the url manually then what you want to do is send the file to the browser with the http header "Content-type" set to "application/octet-stream".

header('Content-type: application/octet-stream');
echo $file;
exit;

Alternatively you could just direct the users browser to the remote file but then the server would have to configured to set the content-type header to octet-stream. This would ensure that the popup is shown rather than the browser performing some other action such as displaying the image or opening an external program.

BTW it's easy to see why your getting that 404 not found error by looking at the address bar.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM