0

When I use window.open(); in my lightning controller, it opens the URL but at the end of the salesforce's url. It does open in a new tab which is what I want but the url is confusing me.

For example, if my URL is "www.google.com"; window.open() is pushing the url into: "https://mydevenviornment--dev4.lightning.force.com/lightning/r/Opportunity/0061h00000Aq3z7AAB/www.google.com"

What gives? Shouldn't it just be opening the URL in its own tab and solely as www.google.com?

Here is the code:

({
doInit: function(component, event, helper) {
    component.set("v.Spinner", true);
    let action = component.get('c.callExpress'),
    recordId = component.get('v.recordId');
    action.setParam('opptyId', recordId);
        action.setCallback(this, function(result) {
            try {
                let state = result.getState();
                if (state === 'SUCCESS') { 
                    let expressURL = result.getReturnValue(); 
                    var dismissActionPanel = $A.get("e.force:closeQuickAction");
                    dismissActionPanel.fire();
                    window.open(expressURL); //expressURL is www.google.com
                } else if (state === 'ERROR') {
                    var dismissActionPanel = $A.get("e.force:closeQuickAction");
                    dismissActionPanel.fire();
                    var errors = result.getError();
                    alert(errors[0].message);
                }
            } catch(e) {
                console.log('e: ' + e);
            }
        });
        $A.enqueueAction(action);
},
  • 1
    shouldnt you be using navigation events instead? – glls May 6 '19 at 1:36
  • when I use navigation events, it still generates the weird URL but also populates the URL in a salesforce sub tab rather than a new browser tab. – Olivia May 6 '19 at 2:02
3

That's expected. If you don't include the fully qualified URL, window.open assumes you meant "open a URL on the current domain." To open the URL correctly, it should be in the form of https://www.google.com/.

  • thank you. it was the https:// I was missing. this worked – Olivia May 6 '19 at 12:22
0

Could You please provide what exactly you are returning from server side code. Looks like you are appending Opportunity Id to URL as you are passing it as parameter to you method.

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.