Question

I have this XAgent with seems to work fine but it opens it in the CURRENT browser. How would I open it in a new window?

This code is running in After RenderedResponse of an XPage.

Thanks

// Track Downloads

// Setup XAgent stuff
var exCon = facesContext.getExternalContext(); 
var writer = facesContext.getResponseWriter();
var response = exCon.getResponse();

var fileLink = param.get("link");

// Insert Logging Code here

facesContext.getExternalContext().redirect(fileLink);

writer.endDocument()
Was it helpful?

Solution

Looks like you are trying to track when somebody clicks on the download link.

Without tracking the link would have been pointing directly at the file causing the browser to initiate the download and the user would stay on the current page. With the XAgent tracking in place the user is going to a different page in the application to do the tracking and initiate the download.

You could add a target of '_blank' to the initial link that is calling the XAgent. This will cause a new window/tab to open in the users browser but it will close once the download initiates.

Using this method of tracking the downloads will, however, remove the ability for the user of the site to be able to right click on your download link and do a 'save as'.

OTHER TIPS

For a download link you could also consider to just stream the file using the OutputStream (there only can be one: Writer or Stream!) to directly serve the bytes of the file to download. You need to set the MIME type in the header. If it is not a file type the browser can handle, the download dialog will appear anyway. Opening a new window is actually considered bad style these days. If a user wants a new Window there is Ctrl+Click and Shift+Click -> a decision you shouldn't make for them (which opens the can of worms of browser illiterate users).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top