I would open a link in a lightning component in another tab. Here is the code:
showAttachment : function(component, event, helper) {
var idContentVersion = event.getSource().get("v.title");
console.log(idContentVersion);
var action = component.get("c.viewContentDocument");
action.setParams({
idContentVersion: idContentVersion
});
action.setCallback(this, function(response) {
var status = response.getState();
if (component.isValid() && status === "SUCCESS") {
event.getSource().set("v.value", "one/one.app#/sObject/ContentDocument/"+response.getReturnValue());
var urlEvent = $A.get("e.force:navigateToURL");
urlEvent.setParams({
"url": "one/one.app#/sObject/ContentDocument/" + response.getReturnValue(),
"target": "_blank"
});
urlEvent.fire();
}
else {
console.log('Error: ' + status);
}
});
$A.enqueueAction(action);
}
I tried to add "target": "_blank"
as event's parameters but it doesn't work.
This method is called by clicking on a link:
<ui:outputUrl aura:id="urlFile" label="" value="" target="_blank" click="{!c.showAttachment}"/>
.
How can I resolve this problem?
Best Answer
As far as I understand, the navigation event will use the same window/tab if you give it a URL inside your salesforce instance. So, to get what you want, I think you could just use plain JS:
Sounds like you really do want a new window/tab, but in case you haven't seen it, there is an event you fire to preview Content in a lightbox kind of thing:
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/ref_lightning_openFiles.htm