0

Basically I hate having to change the header code along with the page title located in the <title> tags in the header.... Is there JavaScript or perhaps HTML that I can use that automatically sets a certain <p> in the header to be equal to the page title?

Wold
  • 952
  • 1
  • 13
  • 25
jspinella
  • 2,013
  • 3
  • 25
  • 39

1 Answers1

2

Yes, you can do that with Javascript, but if you are thinking of SEO (search engine optimization), then you wouldn't want to.

A search engine doesn't execute the script in the page, so it would not see the header the way that a visitor using a browser would. It would see the header without the title added, and that would be bad for the search engine listing, because the header is an important factor when the search engine determines what the page is about.

Anyway, if you still want to do it, here is an example of code that puts the title in an element with the id title:

window.onload = function(){
  document.getElementById('title').innerHTML = document.title;
};
Guffa
  • 687,336
  • 108
  • 737
  • 1,005