1

As I understand it right we are supposed to not use href="/..." attributes anymore in Lightning and have onclick="{c.navigateToSObject}" instead.

navigateToSObject: function(cmp, event, helper) {
        event.currentTarget.id;
        var evt = $A.get("e.force:navigateToSObject");
        evt.setParams({
            "recordId": recordId,
            "slideDevName": "detail"
        });
        evt.fire(); 
    }

But how do I get Command-Click (on Mac) to work with that?

According to this https://success.salesforce.com/ideaView?id=08730000000CIt7AAG it seems to be possible and is perfectly working for all links generated by the Salesforce UI. Just CMD-click any lookup field on a record page.

0
-1

Here is example how to detect if CTRL key is pressed: Any way to detect keyup and keydown events NOT using an input field?

You can also use Salesforce url like here: Open link in another tab with e.force:navigateToURL

I did not try on mac, but on windows this works for me:

if(event.ctrlKey) {
    window.open('https://www.google.com','_blank');
} else {
    window.location.assign('https://www.google.com');
}

If you want to navigate to sObject, use url like this:

one/one.app#/sObject/0060E00000XXXXXXXX

If you want to navigate to custom component, you can do some trick to get url. In your url one/one.app#eyJjb... symbols after # is base64 json that decoded looks like this:

{
    "a:t": 1496392690947, // time when opened
    "attributes": {
        "values": {
            // your component attributes
            }
        }
    },
    "componentDef": "c:YourComponent"
}

So you can try to generate your json data, base64 encode and redirect to it.

To see your url decoded and parsed in lightning app, try this:

JSON.parse(atob(window.location.hash.split('#')[1]))
9
  • As I understand the solutions they don't provide the option to open a link in a new tab but enforce it all the time. What I need is a way to open it in a tab when the user does a CMD-Click. Jun 2 '17 at 10:49
  • How would I have to convert my <a onclick="{!c.handler}"> to make that work? Jun 2 '17 at 11:08
  • Does it work if you put code that redirects in handler method in controller? Jun 2 '17 at 11:20
  • Sure. I can do that. Jun 2 '17 at 11:22
  • So what is still the problem? Jun 2 '17 at 11:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.