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
Prodly Developers 4Prodly Developers 4 

Lightning page URL get parameters

Hello All,
I am trying to get lightning page URL using (window.parent.location). I am facing cross domain error.
Is there any solution to get lightning page URL and get parameters from lightning URL?

Thanks
GauravendraGauravendra
Try using this:
var locUrl = window.location.href;
        alert('locURL : '+locUrl);

 
{!pramod_nishane}{!pramod_nishane}
Hi Prodly Developers 4,

Using "window.location.href" you can get whole URL and you can build your own logic to parse that URL and use that parameters whenever required.

In below code i am just showing you how to parse URL.
You can process more as per your implementation.

Try this:

********Component:-
<aura:component controller="AccountByID" implements="forceCommunity:availableForAllPageTypes" >
    <aura:attribute name="para1" type="String"/>
    <aura:attribute name="para2" type="String"/>
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />

    Parameter 1 :- {!v.para1}
    Parameter 2 :- {!v.para2}

</aura:component>

********Client-side Controller:-

({
    doInit : function(component, event) {

        var action = component.get("c.AccById");
        action.setCallback(this, function(a) {
        var strtoken = window.location.href; // get whole URL
        var strId = strtoken.substr(strtoken.indexOf('?') + 1); // you can build you own login to parse that URL and get the parameters required
        var arrStr = strId.split('&');
        console.log('Parameter 1 ***** '+arrStr[0]);
        console.log('Parameter 2 ***** '+arrStr[1]);
        var sParameterName;   
        for (var i = 0; i < arrStr.length; i++) {
            sParameterName = arrStr[i].split('=');   
        }
        console.log('sParameterName Length ***** '+sParameterName.length);   
            
        component.set("v.para1", sParameterName[0]);
        component.set("v.para2", sParameterName[1]);
       });
        $A.enqueueAction(action);       
    }
})



Let me know in case of any concerns.

Please mark this answer as the solution/ best answer if it solves your purpose so that it can help other community members.

Thanks,
Pramod Nishane
Salesforce Consultant
Varasi LLC
www.varasi.com