我想在我的代码的每个页面中更改标题但是当我查看源代码时,我仍然会看到旧标题。 这是我的代码:
window.onload = function (){
setProductMeta();
}
function setProductMeta(){
var des = document.getElementById("description").setAttribute("content","dynamic meta description");
document.getElementById("keywords").setAttribute("content","dynamic meta keywords");
document.title = "Point of Sale System";
}
以及上面的这个元数据
<title>Welcome to Atmostphere Technology</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta id="title" name="title" content="Welcome to Atmostphere Technology" />
<meta id="description" name="description" content="atmos is best service in cambodia" />
<meta id="keywords" name="keywords" content="atmos is best service in cambodia" />
答案 0 :(得分:0)
服务器将源代码传递给浏览器。
浏览器将标记转换为DOM。
然后 JavaScript运行并执行您执行的任何DOM操作。它永远不会涉及源代码。
虽然使用JavaScript更改标题有时很有用(例如Facebook用它来表示自上次与页面进行交互以来的警报数量),但几乎所有使用元数据的内容都不会执行JavaScript。如果您想要更改页面的基本内容,请在源代码中进行,而不是使用客户端编程。