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?
Asked
Active
Viewed 194 times
0
-
Can you provide your code for better understanding of your query – Chelseawillrecover Oct 27 '13 at 21:32
-
Similar question: http://stackoverflow.com/questions/1057059/how-to-get-title-of-html-page-with-javascript – atroutt Oct 27 '13 at 21:34
1 Answers
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
-
Thank you, I appreciate you telling me why it would be a bad idea, I'll be sure to avoid it. – jspinella Oct 28 '13 at 00:22