次のコードを使用して、30 秒ごとに最新のページ タイトルを自動的に取得/設定します。
<script type="text/javascript">
setInterval(function() {
var data = "http://mysite.com/mypage.php";
$.get(document.location.toString()).then(function (data){
//find and set the title of the page
document.title = data.match(/<title>(.+)<\/title>/)[1];
});
}, 30000);
</script>
アンパサンドを含むタイトルを除いて、うまく機能します。これらは通常どおりロードされ、30 秒後に次のものに置き換えられます。
&
したがって、ページのタイトルが次の場合:
Fun & Games
30 秒後、次のようになります。
Fun & Games
ありがとう