+ Start a Discussion
Ken Koellner 1Ken Koellner 1 

open record in new tab with Lightning component

I'm coding a Lighning component.  I can allow the user to navigate to a record with e.force:navigateToSObject but that will always load it in the current tab.  

If I want the user to optionally (or always) open the record in a new tab, is there a preferred method of doing it?  Or is it even advisable.

I thought maybe including a regular HTML hyprlink like -- /one/one.app#/sObject/0066A000002ycK8QAI/view would do it.  Then the user could right-lick and open in new tab.  I don't know if there's a better way.  Or perhaps because mobile apps like Salesforce1 always operate in one window, whether it might not be a could idea to even try that (the link would then launch the user's mobile browser and the record would open there rather than in the SF1 app).

Thoughts?

-Ken
 
Zuinglio Lopes Ribeiro JúniorZuinglio Lopes Ribeiro Júnior
Hello Ken,

You're right! Whenever is possible avoid opening a new  window/tab in your application. But if you really need there is no other option but using a anchor (a) or a button with the attribute target='_blank' as an example. Be aware that there was a know issue regarding the target attribute with the Lightning LockerService which is supposedly fixed by now. 

​Hope to have helped!

Regards.

Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.
 
Ken Koellner 1Ken Koellner 1

Good answer.  One additional thought.  Is there a way to detect whether the user is in a browser or the SF1 app now that Lighning is running?  I suspect there must be.  I know before Lightning you could simply put in JS like "if(sforce&&sforce.one){".  Not sure if that will work now if you are in Lightning or whether it will always think you are in sforce.one and you need to inspect something else.

A nice way for it to work would be to conditionally render the link if in a browser but put the onclick navigateToSObject if in the mobile app.

Zuinglio Lopes Ribeiro JúniorZuinglio Lopes Ribeiro Júnior
Hello Ken,

I wouldn't rely on javascript to detect that. Try using the UITheme instead:
https://developer.salesforce.com/blogs/isv/2016/04/introducing-ui-theme-detection-for-lightning-experience.html

Hope to have helped!

Regards.

Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.