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
SampathNamburiSampathNamburi 

Current Page URL

Hi,

May i know how i can access the full page URL into a variable in a component? I am writing a custom apex page which call a custom component. My custom apex page will be called in a framed environment. (Header, left side menu and my Apex page will be in the right side wide frame). On the first load of the page i would like to grab the main url. I have tried the below but they are not addressing my issue. Any help on this is highly appreciated.

 

Page_URL__c= ApexPages.currentPage().getUrl() - This is giving me the custom apex code path (apex/CSP_Tracking) not the main page url which should be https://cs3.salesforce.com/home/home.jsp

 

Page_URL__c = ApexPages.currentPage().getHeaders().get('Host') - This is giving me cs3.salesforce.com but i am interested to get the rest of the URL which is "/home/home.jsp"

 

Thank you,

Sampath

Best Answer chosen by Admin (Salesforce Developers) 
ca_peterson_oldca_peterson_old

The frames are what is causing the issue here, your apex runs in the context of the frame, so it's returning the right URL. The end user's browser is the only thing that knows the current top-level page URL, your code inside the frame has no way of knowning that.

 

You're going to have to use javascript for this, which means it's not available in the page controller without some extra effort to post it back after the page loads.