3

i have created VF page and shown that page in home components sidebar. Now my requirement is to show the browser current URL address on Sidebar component VF page.

Now its showing current VF page URL like: https://c.ap1.visual.force.com/apex/geturl?core.apexpages.devmode.url=1

But i want to the browser current address in VF Page like : https://ap1.salesforce.com/001/o

Any one please help me to over come this problem.

7

If your page is using a controller or extension (if it's not, just create an extension) then you should be able to get the URL you're after using the referer header for the Visualforce page.

Use the following method to get the URL:

public String getReferer()
{
    return ApexPages.currentPage().getHeaders().get('referer');
}

Then you can just get this in your page using:

<apex:outputText value="{!Referer}"/>
| improve this answer | |
  • Dear LaceySnr, Thanks you Very very much to your support. It solved my problem. thanks & Regards Mylife.... – mylife525 Nov 22 '12 at 10:38
  • If this is the HTTP referer header will it be the current page that the user is on or the previous page that they navigated here from? From the PageReference Docs - "The URL that is either included or linked to the current request's URL. This header is optional." I might be missing something with how the sidebar works. – Daniel Ballinger Nov 22 '12 at 19:17
  • 1
    @DanielBallinger When you put VF in the side bar you do so via an iFrame, and so the referer is the parent URL which is the one sought after here. – Matt Lacey Nov 24 '12 at 3:43
1

If you're using a Controller, you can use the System.URL class to grab the base URL

Public String baseURL =   URL.getSalesforceBaseUrl().toExternalForm();

You can then bind apex:outputText to this controller variable.

| improve this answer | |
  • Dear techtrekker, Thanks for your replay, I tried your solution. But still I am getting the same problem. I am showing controller code and snap shot of my issue. public string BrowserURL = System.URL.getSalesforceBaseUrl().toExternalForm(); public string getgraburl() { return BrowserURL; } can you please suggest me how can i achieve this problem. thanks mylife.... – mylife525 Nov 22 '12 at 10:15
  • You can use the String replace function to get rid of the 'c.' and 'visual.force.' And you should get the Base URL. I reckon that is because Visualforce is served up from a different subdomain – techtrekker Nov 22 '12 at 10:38

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.