In an aura component , I am trying to open a new component automatically using window.open but that is taking me to the new tab instaed of being on the same page. I want to be on the same page and open a new tab.

  • what do you mean automatically you should probably share your code where are you putting window.open also How to Ask
    – User6670
    Commented Apr 24, 2020 at 7:03
  • My component : <aura:component implements="force:appHostable,flexipage:availableForAllPageTypes" access="global" > <aura:attribute name="pageReference" type="Object"/> <aura:attribute name="url" type="String"/> <lightning:navigation aura:id="navService"/> <div> I am your first component !! </div> <aura:handler name="init" value="{!this}" action="{!c.mycomp}"/> </aura:component> Commented Apr 24, 2020 at 7:30
  • Controller : ({ mycomp: function(cmp, event, helper) { var navService = cmp.find("navService"); var pageReference = { "type": "standard__component", "attributes": { "componentName": "c__PQRTEST" }, "state": { 'message':'This is the target page' } }; cmp.set("v.pageReference", pageReference); const handleUrl = (url) => { window.open(); }; navService.generateUrl(cmp.get("v.pageReference")).then(handleUrl); } }) Commented Apr 24, 2020 at 7:33

1 Answer 1


There is no standard way to do this like target="_blank" or anything. But there is a hacky way to do this with a little JavaScript

this can be done by simulating ctrl + click (or any other key/event combinations that open a background tab) on a dynamically generated a element with its href attribute set to the desired url

function openNewBackgroundTab(){
    var a = document.createElement("a");
    a.href = "http://www.google.com/";
    var evt = document.createEvent("MouseEvents");
    //the tenth parameter of initMouseEvent sets ctrl key
    evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0,
                                true, false, false, false, 0, null);
  • Actually , I need to get it opened automatically and not with any click Commented Apr 24, 2020 at 6:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .