function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
meghna nmeghna n 

open external url as inline in lightning

Hi

I am having a piece of code that will open an external URL.

whhen I click the button it will open the URL in a web tab on the browser.

here's the code
 <a href="javascript:void(0);" onclick="{!c.openMyProviderPage}">Find provider</a>  

In the controller of the component

 openProviderPage : function(component, event, helper) {
        debugger;
         var pageUrl = component.get("v.findMyProviderURL");
        var urlEvent = $A.get("e.force:navigateToURL");
        urlEvent.setParams({"url": pageUrl });
        urlEvent.fire();
       
I do not want the new URL to open in a separate browser window i.e the new URL should open as a subTab inline.

I hope my requirement is clear.

Please help me out at earliest.


 
Best Answer chosen by meghna n
sfdcMonkey.comsfdcMonkey.com
as per my understanding you can't open any exteranl URL in salesforce instance like this. so '$A.get("e.force:navigateToURL")' is the only option to open external link in new browser tab.

or you can use 'window.location.href = 'https://www.xyz.com';'  but this will replace the current tab URL with this new link.

Thanks 

All Answers

Lokesh KumarLokesh Kumar
Use 
window.open(pageUrl);

 
meghna nmeghna n
@Lokesh

I need to navigate to this url : https://www.superb.com/dsepublic/#/contentPage?page=providerSearchLanding&site_id=medicare

In your approach it does open into a new Tab but also a new browser tab opens. I do not want the browser tab to open, it should be as a separate tab only within salesforce.

Also since the above url is not a part of salesforce lightning it also throws a error.

I tried a different approach.
I created a lightning component, in the doInit event used force:navigateToUrl, then created an app builder page and dragged and dropped the component in the app builder page.

Then I executed the app builder page from the link, it will open a new Tab along with a separate browser tab also. This is not my requirement.

Please let me know any feasible solution .

thanks
meghna
sfdcMonkey.comsfdcMonkey.com
as per my understanding you can't open any exteranl URL in salesforce instance like this. so '$A.get("e.force:navigateToURL")' is the only option to open external link in new browser tab.

or you can use 'window.location.href = 'https://www.xyz.com';'  but this will replace the current tab URL with this new link.

Thanks 
This was selected as the best answer
meghna nmeghna n
@piyush , @ Lokesh
It is not possible top open and external URL as a salesforce TAB by using force:navigateToUrl. 

Thanks for the idea.
 
Pavan NichenametlaPavan Nichenametla
Hi Meghna, Did u find any solution for it? I have similar requirement
setu nemasetu nema
Web Tab will server your purpose and you have option to open in salesforce window itself.