我刚刚在谷歌浏览器中打开了一个空白的HTML页面,其中包含一些基本标签(如html,body,head等),并尝试在控制台中执行以下命令:
history.pushState(null, 'my test title', '/test/url');
Run Code Online (Sandbox Code Playgroud)
历史事件工作正常,但页面标题保持不变.可以吗?我应该每次都手动更换吗?如果我应该,为什么像title这样的pushState()方法中有这样的参数?
如何使用Jquery修改文档的现有标题作为鼠标悬停标题更改,就像在Facebook标题链接上那样.
有没有办法检测到document.title/ head > title通过Javascript 的更改?我想通过Google Chrome扩展程序内容脚本检测到这一点,因此我无法在目标页面的JS中实际连接执行标题更改的代码.
我发现WebKitMutationObserver理论上应该能够检测到更改head > title,但它并不适用于所有情况:
// set up an observer for the title element
var target = document.querySelector('title');
var observer = new WebKitMutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
console.log(mutation);
});
});
var config = { attributes: true, childList: true, characterData: true };
observer.observe(target, config);
// this jQuery statement fires the observer as expected ...
$('head > title').text('foo');
// ... but this doesn't:
document.querySelector('title').innerText = 'cheezburger';
// ... and neither does this:
document.title = …Run Code Online (Sandbox Code Playgroud) 我对这个问题有疑问,让我们说我的页面加载 是
<title>Test Only</title>
Run Code Online (Sandbox Code Playgroud)
我改变了 使用javascript的值
<title>Test Use JS Change</title>
// this is my Javascript code to update the <title> value after page load
$(function(){
$('title').html('Test Use JS Change');
});
Run Code Online (Sandbox Code Playgroud)
我是否知道搜索引擎机器人,他们会将我的头衔识别为Test Use JS Change或Test Only
这是因为当我看到浏览器tab/inspect元素来查看动态源时,标题已经更新,但是当我纯粹只查看源时,它会显示我定义的默认标题.
需要一些关于此的建议.谢谢!
可能重复:
如何动态更改网页标题?
我正在尝试使用JavaScript设置我的网页标题,因为我希望存储在localStorage中的某些内容成为标题的一部分.我正在尝试的方法是使用document.createElement('title'),但是当我这样做时,我无法设置标题的文本.有没有办法以这种方式设置标题的文本,还是有不同的方式我应该这样做?
我想根据我在页面中提取的信息更改页面中显示的标题(例如,显示收件箱消息的数量)
document.getElementsByTagName('title')[0].innerHTML="foo"; 确实更改了标题标记,但是当发生这种情况时,firefox不会更新显示的标题(在窗口和标记中).
这可能吗?
我想根据内容更改 HTML 页面的标题,但我只包含标题部分下方的内容,所以我必须从这个包含的 php.ini 更改标题。解释:
<html>
<header><title>I would like to change</title></header>
<!--CONTENT-->
<?
include "pages/some_page.php";
?>
</html>
Run Code Online (Sandbox Code Playgroud)
我怎么能那样做?任何人都可以帮忙吗?
我想做的事情是当用户写入一些内容并提交时,页面将更改为输入。
例子:
如果用户在输入中写入“Web”,则页面标题应更改为“Web”
这是代码:
JS:
document.getElementById("titleSumbitBtn").onclick = function (){
var newTitle = document.getElementById("newTitle").textContent;
document.getElementById("title").innerHTML = newTitle;
}
Run Code Online (Sandbox Code Playgroud)
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title id="title">Web Editor</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<center><label id="originLabel">Welcome to Web Editor!</label><br></center>
<br><label id="changeTitleLabel">Change the title of Web: </label><br>
<input type="text" id="newTitle"><br>
<button type="button" id="titleSumbitBtn">Change</button>
</body>
</html>
Run Code Online (Sandbox Code Playgroud) 我想使用标题标签在浏览器中显示标题。我用了
<script>$(document.title).html('title');</script>
Run Code Online (Sandbox Code Playgroud) javascript ×5
html ×3
jquery ×3
firefox ×1
greasemonkey ×1
html5 ×1
page-title ×1
php ×1
seo ×1
title ×1
webkit ×1