我想在我的网站上有一个Facebook功能: 每当用户收到私人消息时,标题应该改为“[1 PM] TITLE”,
怎么做?
答案 0 :(得分:1)
您可以使用Page.Title
属性动态设置标题
请看这个链接 - 也许可以帮助你进一步
Specifying the title meta tags and other html headers in the master page
修改强>
如果你可以通过代码改变你的标题,那么上面就可以了。您可以根据您拥有的数据在Page_Load
函数中更改它。
如果您想在页面加载并发送到客户端后更改标题,那么唯一的方法是通过javascript。如果标题需要服务器端数据,则AJAX将是最方便的方式(不要仅仅为了更改标题而回发所有页面)。当数据返回到客户端时,您可以执行document.title = <new title value>
,它会随时更改。
答案 1 :(得分:1)
您可以在HTML标记中尝试这样的事情(我现在无法测试......):
<head id="head1" runat="server">
<title>To be replaced.</title>
</head>
ASPX代码隐藏:
// Add the page title to the header element.
Page.Header.Title = "HtmlHead Example";
答案 2 :(得分:1)
最简单的方法是通过javascript,例如:
<script type="text/javascript">
document.title = "This is new title";
</script>
你可以将它包装成某个函数并在需要时激活它:
<script type="text/javascript">
function changeTitle(str) {
document.title = str;
}
// fire it when you need:
changeTitle("[1 PM] TITLE");
</script>