Is there anyway to link the <title> to a <div> via javascript or php?
I tried
document.title.valu开发者_JAVA技巧e = document.getElementById("div").innerHTML;
but that didn't seem to work
I want to do this because I have multiple pages where I want the <title> to the be the same as what is in a <div>, but I don't want to handcode it.
You don't need document.title.value, just document.title works.
document.title=document.getElementById("div").innerHTML;
Offcourse, you need to execute this after your DOM loaded. Use the onload in the body or any onload function.
You don't need .value on the document.title. I would also use .innerText instead of .innerHtml.
加载中,请稍侯......
精彩评论