如何使用 JavaScript 在文档标题末尾添加一些文本?
How to add some text to end of document title with JavaScript?
我有这样的基本 html:
<html>
<head>
<title>Page name @</title>
</head>
</html>
在“@”之后我需要有域名 ("EKS.RU"),我认为 JS 是解决该问题的最佳方案。
因此,如果我需要更改域,我需要在一个脚本文件中简单地编辑部分文本。
您确实可以使用 Javascript 来做到这一点,您所要做的就是找到 title 属性,然后将 window.location.hostname
添加到它的文本中,这将 returns这一页。
document.title += window.location.hostname;
document.title这很容易:
var domain = 'your.domain';
document.title += domain;
只需将域变量更改为您想要的任何值即可。还要确保将其放在脚本标记中,就在结束正文标记之前,以防您向其中添加其他代码。
您可以使用 document.title
来 获取 和 设置 页面标题,因此对于您的情况,您可以执行类似这个。
document.title += "EKS.RU";
您可以简单地附加如下值:
document.title += "this text added at the end of title";
我有这样的基本 html:
<html>
<head>
<title>Page name @</title>
</head>
</html>
在“@”之后我需要有域名 ("EKS.RU"),我认为 JS 是解决该问题的最佳方案。
因此,如果我需要更改域,我需要在一个脚本文件中简单地编辑部分文本。
您确实可以使用 Javascript 来做到这一点,您所要做的就是找到 title 属性,然后将 window.location.hostname
添加到它的文本中,这将 returns这一页。
document.title += window.location.hostname;
document.title这很容易:
var domain = 'your.domain';
document.title += domain;
只需将域变量更改为您想要的任何值即可。还要确保将其放在脚本标记中,就在结束正文标记之前,以防您向其中添加其他代码。
您可以使用 document.title
来 获取 和 设置 页面标题,因此对于您的情况,您可以执行类似这个。
document.title += "EKS.RU";
您可以简单地附加如下值:
document.title += "this text added at the end of title";