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
JK84JK84 

How to get Page Title in VF using Javascript

Hi,

 

I'm trying to get the title of the page in a VF page using Javascript (code is as follows) :

 

But, the alert is only displaying "Salesforce.com - Developer Edition", although I can see that the title in the "view Source" of the page is "<title>Candidates: Home ~ salesforce.com - Developer Edition</title>"

 

Any suggestions on where am I going wrong ?

 

<script type="text/javascript">

window.onload =  function jfunction()
 {
        
       var pageTitle =  document.getElementsByTagName("title")[0].innerHTML;
       alert('page Title '+document.title);

}

</script>

 

Puja_mfsiPuja_mfsi

Hi,

It's working fine for me. can you plz tell me where you have put your java script in VF page or any custom button java script.

JK84JK84
Hi,

I have the javascrip in a VF page and it is as follows :

<apex:page controller="NewAuditController" action="{!updateData}">

&lt;script type="text/javascript">

window.onload = function jfunction()
{
var pageTitle = document.getElementsByTagName("title")[0].innerHTML;

alert('page Title '+pageTitle );


}

&lt;/script&gt;
....
asish1989asish1989

In your vf page add 

<title> Your Page Name</title>

 

var pageTitle = document.getElementsByTagName("title")[0].innerHTML="Your Page Name";

JK84JK84

I guess I missed adding an important point in the question. I was trying to fetch the title of the referrer URL, but not the current page URL.

 

The code I've written is displaying the current page URL, but how do we get the referrer page title in javascript?