laredotornado wrote on 23 aug 2010 in comp.lang.javascript:
I have a link
<a href="download.pdf">Download</a>
and I'm interested in capturing the event when someone right-clicks on
the link and opens it in a new window/tab. Any advice you have is
greatly appreciated, - Dave
A new window/tab can also be forced in many browsers by a shift-click.
I do not see what right you have to know what way I look at the pdf.
So I am glad browser security does not allow you to see that in clientside
javascript.
However, perhaps if you had some "stay-alive" ajax connection to the
server, you could see serverside if the original page was or was not
overwritten by the pdf.
Forcing the page to be on a new window or tab can be done like this:
<a href='download.pdf' target='_blank'>Download</a>
Forcing the pdf to be downloaded and not shown in the browser,
can be done streaming the pdf with serverside javascript,
specifying "attachment":
<% // Javascript presumed
.....
var filePath = 'download.pdf';
var temp = 'attachment;filename=' + filePath;
Response.ContentType = 'application/pdf';
Response.Addheader('Content-Disposition', temp);
.....
%>