简体   繁体   English

如何使用有效标记维护动态页面标题?

[英]How to maintain a dynamic page title with valid markup?

Currently in my code I have something like this outside of the HTML head tag: 目前在我的代码中我在HTML头标记之外有这样的东西:

<title>My Website - <?php echo $row['title']; ?></title>

This works but does not validate with w3 because with XHTML titles can only be modified within the HTML head tag. 这有效,但不会使用w3验证,因为XHTML标题只能在HTML头标记中修改。

How does one solve this? 如何解决这个问题? I want to maintain 100% valid XHTML Strict markup which I currently have but I don't want to use any messy hacks either. 我想保持100%有效的XHTML严格标记,我目前有,但我不想使用任何凌乱的黑客。 I read that changing the website title with Javascript after the page loads is bad practice but it seems like the only viable option here. 我读到在页面加载后用Javascript更改网站标题是不好的做法,但它似乎是唯一可行的选项。 What does SO think? SO的想法是什么?

如果您粘贴在PHP完成执行后呈现的HTML(在验证器中),则应该正确验证(假设您将标题标记放在正确的位置[又名<head></head>标记])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM