I am trying to capture the URL of the previous page in a custom VF Page, when someone clicks on my custom tab from any page, especially when they are in Setup or Reports area. Following is what I am trying to do, which is not giving me the desired results. I’ll appreciate if anyone can provide any insights on this.
My goal is to capture the previous page url, execute my logic on my custom VF page, and redirect the user to the same previous page.
I have a Custom Tab ‘Check URL’ that displays the custom VF Page. I want to display the following url in the case of click the tab from setup area:
The code is as follow:
<apex:page standardStylesheets="true" sidebar="false" showHeader="false">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
var j$ = jQuery.noConflict();
j$(document).ready(function() {
var oldURL = document.referrer;
alert(oldURL);
});
</script>
<h1> {!$CurrentPage.URL}</h1>
<p>
<a href="javascript:history.go(-1)" title="Return to the previous page">« Go back</a>
</p>
</apex:page>